Categories
Search WordPress

WordPress Exclude pages from search

function chet_tips_modify_search_filter($query) {

  if ($query->is_search) {

    $query->set('post_type', 'post');

  }

  return $query;

}

add_filter('pre_get_posts','chet_tips_modify_search_filter');
Categories
Search WordPress

WordPress Exclude categories from search

function chet_tips_search_filter($query) {

  if ( $query->is_search && ! is_admin() ) {

    $query->set('cat','8,15'); 

  }

  return $query; 

}

add_filter('pre_get_posts','chet_tips_search_filter');