WordPress Icon Logo
me@grafxflow

Written by me@grafxflow

18 Mar, 2013

0

1,874

Hide posts/pages from search results

If you want to hide certain pages or posts from the WordPress search results. Then you need to edit the functions.php file.

At first open the file and add this function. In the array you need to add the relevant post or page id number to the array. So for example below 1,5 and 10.

function SearchExcludeFilter($query) {
    if ($query->is_search) {
        $query->set('post__not_in', array(1,5,10));
    }
    return $query;
}

add_filter('pre_get_posts','SearchExcludeFilter');

Add comment

Smart Search

119 Following
50 Followers

me@grafxflow

Hull, United Kingdom

I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Follow