Exclude specific category posts in WordPress search results
Updated On May 23, 2015 October 16, 2012 -Written ByBy default, WordPress search will display relevant results from entire post content on your website. Do you want to stop specific posts from appearing in WordPress search results? This can be easily implemented using piece of custom code.
Code to exclude category in WordPress search results
1. To get started, assign specific category to all posts that you want to exclude (or hide) from appearing in WordPress search results listing.
2. Then add following code to functions.php file.
is_search && !is_admin() )
$query->set( 'cat','-7' );
return $query;
}
In above code, change 7 with ID of the category that you want to exclude in WordPress search results listing. Quick and simple, isn’t it? [Credit Jared Atchison]