Lego2012
12/13/2016 - 10:04 AM

Search - Exclude pages from search

Search - Exclude pages from search

<!-- Same story goes for pages we you might want to keep out of results. So, add the following code to your functions.php file: -->

function modify_search_filter($query) {
  if ($query->is_search) {
    $query->set('post_type', 'post');
  }
  return $query;
}

add_filter('pre_get_posts','modify_search_filter');

<!-- You can use this on your blog to let readers just browse and look for your single posts, leaving out all pages they've no intertest in reading. -->