(+84) 463.28.7979

How to Exclude Pages from WordPress Search Results

By default, WordPress Search feature displays published posts and published pages in search results. Often when users are looking for something in a blog, it is most likely a post rather than a page. In this article, we will show you how to make your search more relevant and less crowded by excluding pages from WordPress search results.

First open your theme’s functions.php file and paste this code:

function SearchFilter($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘post’);
return $query;


Explanation: This code just searches for posts through setting the post_type. You can also make it do the opposite by setting the post_type to pages, so it only return pages in the search result.

Source: Bavotasan

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>