hide certain wordpress pages or posts from search

Some time you don’t 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.

hide certain wordpress pages or posts from 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 to 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' );

hide certain wordpress pages or posts from search

hide certain wordpress pages or posts from search

One Comment

Add a Comment

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