Say "Hello!"

  • This field is for validation purposes and should be left unchanged.

Exclude Posts or Pages from WordPress Search Results

Web Hosting at Bluehost Affiliate Disclosure

1
2
3
4
5
6
7
8
9
//exclude posts from search
function SearchFilter($query) {
    if ($query->is_search) {
        $query->set('cat','0,1');
    }
    return $query;
}

add_filter('pre_get_posts','SearchFilter');

Back to Snippets Follow me on GitHub

Ashley Cameron logo
Blog