How to: Exclude posts or pages from search results ?

Would you like to be able to control which post or pages must be exclued from searches on your WordPress blog? If yes, this recipe will probably help you a lot. Just read on.

Copy and pase this code in your themes function.php file

// search filter
function fb_search_filter($query) {
if ( !$query->is_admin && $query->is_search) {
$query->set('post__not_in', array(1805,1130) ); // id of page or post
return $query;

add_filter( 'pre_get_posts', 'fb_search_filter' );

Save File.

Enjoy code!


Sr. Software Engineer

Posted in Wordpress

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Recent Posts
%d bloggers like this: