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.