Quantcast
Channel: Refreshingly Blue » Uncategorized
Viewing all articles
Browse latest Browse all 2

Exclude Individual Pages From WordPress Searches

$
0
0

There is plenty of information on how to exclude certain categories from WordPress Searches but it is very hard to find anything on how to exclude individual posts or pages from the search results. All you need to do is add a search filter to your functions.php file in your WordPress theme that looks like this:

function searchFilter($query) {
  if ($query->is_search) {
    $query->set('post__not_in', array(13,14,15));
  }
  return $query;
}
add_filter('pre_get_posts','searchFilter');

Just change 13,14,15 to whatever page (or post) ids you would like to exclude from the search. Do not put the numbers in quotes.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images