Return to Snippet

Revision: 27301
at June 2, 2010 01:53 by creativelifeform


Initial Code
function SearchFilter($query)
{
	if ($query->is_search)
	{
		$query->set('cat',-get_cat_ID('CategoryName'));
	}
	return $query;
}
add_filter('pre_get_posts','SearchFilter');

Initial URL

                                

Initial Description
Found this bit of code all over the place, except it missed out a very crucial part of the code which was to add a "-" in front of the ID you wish to exclude.  Add this to functions.php in your theme folder.

Initial Title
Exclude specific category from Search Results in Wordpress

Initial Tags
wordpress

Initial Language
PHP