removing the some wordpress pages or posts from search

Sponsors

Some time you dont want to come the some page and posts come in search. Here is very simple technique for excluding or removing the some wordpess pages or posts from wordpress search.

You just need to put following code in functions.php file. You will find this file in your wordpress theme folder. To work this idea you need to know about the page or post id which you want exclude from search.

When you are creating the post that time you can get the wordpress post id Or while editing the post you will know the wordpress post or page id.


// search filter
function my_search_filter($query) {
 // make sure we are not in the admin and that we are performing a search
 if ( !$query->is_admin && $query->is_search) {
 $query->set('post__not_in', array(50, 10,32,68) ); // IDs of pages or posts
 }
 return $query;
}
add_filter( 'pre_get_posts', 'my_search_filter' );

removing the some wordpress pages or posts from search

removing the some wordpress pages or posts from search

Incoming search terms:

You may like following Articles!

2 thoughts on “removing the some wordpress pages or posts from search

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>