A blog for technology, SEO tips, website development and open source programming.

Exclude pages from WordPress search results

0 556

WordPress Search feature displays published posts and pages in search results, by default. But when users search in a blog for something, it is most likely a post rather than a page. So in this tutorial,  will show you how to exclude pages from WordPress search results and make your search more relevant.

Open your theme’s functions.php file and paste following code:

function mySearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','mySearchFilter');

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More