Skip to main content
2 of 2
added 40 characters in body

Get First Five Posts With Specific Category

<?php
        // the query
        $the_query = new WP_Query(array(
            'category_name' => 'post_category_name',
            'post_status' => 'publish',
            'posts_per_page' => 5,
        ));
        ?>

        <?php if ($the_query->have_posts()) : ?>
            <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
                <?php the_category(); ?>
                <?php the_title(); ?>
                <?php the_excerpt(); ?>
                <?php the_post_thumbnail(); ?>
                <?php the_content(); ?>

            <?php endwhile; ?>
            <?php wp_reset_postdata(); ?>

        <?php else : ?>
            <p><?php __('No News'); ?></p>
        <?php endif; ?>