Wordpress search failed on special characters due to improper decode Wordpress search failed on special characters due to improper decode wordpress wordpress

Wordpress search failed on special characters due to improper decode


Ok, so you do have to decode the search query and here's how I have it working and works like a charm now! This now returns the search results, but keeps the url encoded so no problems anywhere here.

function livchem_search_filter($s) {    return urldecode($s);}add_filter('get_search_query', 'livchem_search_filter');add_filter('the_search_query', 'livchem_search_filter');function livchem_query_vars_search_filter($query){    if ($query->is_search && !is_admin()) {        $query->query_vars['s'] = urldecode($query->query_vars['s']);    }    return $query;}add_action('parse_query', 'livchem_query_vars_search_filter');

As a plus this also works well for path related searches now, so if I added the following to my .htaccess:

RewriteCond %{QUERY_STRING} s=(.*)RewriteRule ^$ /search/%1? [R,L]

Searches would be structured like so: /search/searchterm

And the query with special characters also now works. what a pain in the neck this was to get working properly, for something that is part of the CMS.