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

Snippet Type: PHP

Posted Under: Search

All PHP snippets should be added via a child theme's functions.php file.