ePrivacy and GPDR Cookie Consent by Cookie Consent Exclude wordpress posts or pages from search results - Web design company Romania

All the credit for this bit of code goes to http://www.livexp.net, where it was found.

To exclude one or more categories from WordPress search results, paste this into functions.php of your current theme:

function SearchFilter($query) {
if ($query->is_search) {
$query->set('cat','-1,-10');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');

Guys from www.livexp.net had one small mistake in their code: $query->set('cat','1,10');. Category IDs need to have a “minus” sign to get excluded.