By default, all the search results from WordPress will include pages and posts. However, we might want to be able to exclude pages from the search results, and bring results only from posts. To change this default behavior, it is actually quite simple.
Include the following lines of code in your functions.php file.
[sourcecode language=’php’]
- Advertisement -
function vibeExcludePages($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘post’);
}
return $query;
}
add_filter(‘pre_get_posts’,’vibeExcludePages’);
[/sourcecode]
By adding this bit of code, it will basically tell your search results to not display anything but posts.
- Advertisement -
Here´s one way how to remove pages or categories from search ..
http://tocs-i.com/blog/exclude-pages-or-include-specific-categories-in-wordpress-search/
Good one. Thanks.
Useful trick, thanks for share… 🙂