WordPress Search Filter – How to Exclude Pages from Search Results

https://youtu.be/DPenZ7wGrDw

Learn how to exclude pages from your WordPress search results and instead only show blog posts. By adding some code to our child theme, we can filter search results and only display posts.

Codes used:

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

Share

Related Posts

Leave a Comment

Sign up for Weekly Updates on our Most Read Blog Posts.