How to: Exclude posts or pages from search results
In wordpress the default search it will show all the pages including post and page, but the majority do not want it to show the page as the page: introduction, contact …
Today I will show you how to remove a number of posts, post away from the search results without using the wordpress plugin.
you put this code in the functions.php file:
function SearchFilter($query) {
if ($query->is_search) {
$query->set('cat','-8,-15');
$query->set('p','-8,-15');
} return $query; } add_filter('pre_get_posts','SearchFilter');
the above code will remove the article in the category bearing ID No. 8 and No. 15, and always remove the article, page 18 and 15 bring id anymore.
The test you try, if there is not active, before I use plugin “search-everything” to perform advanced search function, I found this plugin works quite OK. Do you see how the trial offline.