Exclude Individual Pages From WordPress Searches
Posted on July 21st, 2010 in Uncategorized | No Comments »
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.
