Limit WordPress Search Results

We recommend this edit is made to the Child Theme files.

Open functions.php and add this function:

function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('post'));
}
}
add_filter('pre_get_posts','searchfilter');

 

This filters the search results to posts only; it can be modified to display anything (i.e.’page’).

Share On
Scroll Up