Exclude wordpress posts or pages from search results

December 23, 2008 · Print This Article

Would you like to be able to control which post or pages must be exclued from searches on your WordPress blog?

If yes, this article will probably help you a lot.

To achieve this, just simply paste the following code on the functions.php file from your theme.

In this example, your wordpress posts with IDs 1 and 10 will be excluded from your wordpress blog’s search results:


function SearchFilter($query) {
if ($query->is_search) {
$query->set('cat','1,10');
}
return $query;
}

add_filter('pre_get_posts','SearchFilter');


Your choice for site templates and wordpress themes

Comments

One Response to “Exclude wordpress posts or pages from search results”

  1. Exclude wordpress posts or pages from search results | PROWEBDESIGN - professional website design company on January 5th, 2011 6:30 am

    […] the credit for this bit of code goes to http://www.livexp.net, where it was […]

Got something to say?

You must be logged in to post a comment.