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');