Search only posts (not pages) in wordpress

I would like that WP search engine search only posts (now it search posts & pages) – anyone know how to do that?

Related posts

Leave a Reply

1 comment

  1. So first, in the functions.php file in your theme, add this function:

    function is_type_page() { // Check if the current post is a page
    global $post;
    
    if ($post->post_type == 'page') {
        return true;
    } else {
        return false;
    }
    

    }

    Next, in your search.php file in your theme (where your search results are displayed, you want to add the following line right after the loop. It should look like this:

    <?php while (have_posts()) : the_post(); ?>
    <?php if (is_type_page()) continue; ?>