fbpx
How to Exclude WordPress Posts or Pages from Search Results

How to Exclude WordPress Posts or Pages from Search Results

This snippet will allow you to control which posts or pages there should be excluded from WordPress search results.

Instructions
Add this code to your functions.php file.
* In this snippet, posts with the IDs 0 and 1 will be excluded – edit accordingly to suit your needs.

function SearchFilter($query) {
    if ($query->is_search) {
        $query->set('cat','0,1');
    }
    return $query;
}
add_filter('pre_get_posts','SearchFilter');

WordPress Hosting

Leave a Reply

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

WordPress Snippet Info

Tested with Wordpress v. 4.8
Last Modified: 17.05.2017
Last Reviewed: 17.05.2017

How to Exclude WordPress Posts or Pages from Search Results
4.2 (83.33%) 12 vote[s]
Please report broken snippets.
Report Broken Snippet
WordPress Hosting

Recent Comments