Exclude wordpress posts or pages from search results

December 23, 2008

Would you like to be able to control which post or pages must be exclued from searches on your WordPress blog? If yes, this article will probably help you a lot. To achieve this, just simply paste the following code on the functions.php file from your theme. In this example, your wordpress posts with IDs 1 and 10 will be excluded from your wordpress blog’s search results: function SearchFilter($query) { if ($query->is_search) { $query->set('cat','1,10'); } return $query; } add_filter('pre_get_posts','SearchFilter');  Read More →