WordPress Icon Logo
me@grafxflow

Written by me@grafxflow

18 Mar, 2013
0
2,892

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');

Share this article

Add comment...

Smart Search

me@grafxflow Author Profile picture

me@grafxflow

Founder, Grafxflow

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. I build lighting-fast dynamic content engines with Laravel, Winter CMS and Tailwind CSS. Thanks for stopping by!