Limit Search Results For Specific Post Types

Change the default wordpress search, and limit the results to only specific post types.  Change the array that is set to only include the post types that you want returned for the search.


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

return $query;
}
add_filter('pre_get_posts', 'searchfilter');

 

reference: https://www.wpbeginner.com/wp-tutorials/how-to-limit-search-results-for-specific-post-types-in-wordpress/

Close Menu