skip to Main Content

Limit Search Results to Standard (Blog) Posts only

function myprefix_search_filter( $query ) {
	if ( ! is_admin() && $query->is_main_query() ) {
		if ( $query->is_search ) {
			$query->set('post_type', 'post');
		}
	}
}
add_action( 'pre_get_posts','myprefix_search_filter' );
All PHP snippets should be added via child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)
Back To Top