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