fbpx

How to Exclude categories from search

If you want to have a deeper control over the results users can get, you might need a way not to show specific categories within the results page. The use cases are endless: promotional material, press release, translated content, portfolio items, just to name a few. Interested in how to do that? Open your functions.php file and add:

function SearchFilter($query) {
  if ( $query->is_search && ! is_admin() ) {
    $query->set('cat','8,15'); 
  }
  return $query; 
}
add_filter('pre_get_posts','SearchFilter');