Hide Pages from Search Results – Free Code Snippet – Elementor WordPress Tutorial

Add this to Code Snippets to stop Pages from appearing in your Search Results Template. This will show Posts and Products if you want.

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

Join our Mastery Membership

Group Support, Private Facebook Group, and Site Reviews.