Search function works improperly

So I am trying to edit my Search so it searches only for specific categories. I am adding this code to my functions.php file in child theme:

function searchcategory($query) {
if ($query->is_search) {
$query->set(‘cat’,’37’);
}
return $query;
}
add_filter(‘pre_get_posts’,’searchcategory’);

So this is the issue: For example, when I run this code, my search does not even find anything.

Important notes:
1) First of all, I have created several taxonomies and custom post types with Toolset plugin, and these is ID of one of those taxonomies – I am looking up its ID by hovering cursor over the name of taxonomy. Could this be an issue?
2) When I run this code, which supposes to exclude all pages from search results, I still see some of the pages. It is weird.

function SearchFilter($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘page’);
}
return $query;
}

add_filter(‘pre_get_posts’,’SearchFilter’);

Does anyone know what may cause this issue?

Read more here:: Search function works improperly

Leave a Reply

Your email address will not be published. Required fields are marked *