Insert the code snippet into your theme’s functions.php, a helper file, or a functionality plugin to exclude specific categories from being displayed in WordPress search results. Apply the following code snippet to your theme’s functions.php, included helper functions, or a functionality plugin.
X where X is the number/ID of your category, comma separated for multiple.
function SearchFilter($query) {
if ($query->is_search) {
$query->set('cat','-X');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
Share Your Two Cents