Special characters in page list filter

Permalink
I've run across a problem when filtering a select attribute to generate a page list (sent over as a GET request). the attribute select value has an apostrophe (dan's house). The apostrophe is breaking the filter statement:

$pl->filterByAttribute('blog_category', '%'.urldecode($_REQUEST['filter-category']).'%', 'LIKE');


Anyone got any ideas on how I can get around this? just to note I've removed the apostrophe from the attribute value and it works.

 
hutman replied on at Permalink Reply
hutman
What happens if you use this

$pl->filterByAttribute('blog_category', "%".$_REQUEST['filter-category']."%", 'LIKE');
jordanlev replied on at Permalink Best Answer Reply
jordanlev
For select attributes, you should use the "filterBySelectAttribute" method -- it will handle a lot of crapwork for you and ensure that escaping works properly (and works in the most efficient manner depending on single-select or multi-select... e.g. it can be slow to do a LIKE query if there is only 1 value stored in the field).

$pl->filterBySelectAttribute('blog_category', $_REQUEST['filter-category']);


That being said, I'm not sure it will solve your problem with the apostrophes. You'll want to inspect the actual value that is saved in the database and see how it's getting encoded there. Also, how is the filter-category getting encoded in the first place? Maybe try rawurldecode() instead?

-Jordan