WordPress affect categories search form searches – solution 2

Please see this post if you’re only wanting to limit the form to a single category, as it’s as simple as adding a hidden form field.

This solution uses functions.php, adding something like the following:

function SearchFilter($query)
{
if($query->is_search){
$query->set(‘cat’,’0′);
}
}
add_filter(‘pre_get_posts’,’SearchFilter’);

similar post:
http://alexyz.com/wordpress-rss-feed-exclude-categories-or-only-serve-one-particular-category/

http://alexyz.com/wordpress-limit-search-form-to-a-category-2/

similar reference:

http://speckyboy.com/2010/09/19/10-useful-wordpress-search-code-snippets/

Leave a Reply

You must be logged in to post a comment.