I try to make wordpress loop which display two last posts from selected category.
I know there’s so many examples but I don’t find anything working for me.

My code:

    <?php $query = new WP_Query( array( 'cat'=>'2', 'post_count'=>'2', )); ?>
     <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

     <div class="post">
     <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
     <div class="entry-date"><span><?php the_time('d-m-Y'); ?></span></div>
      <div class="entry">
        <?php the_content(); ?>
      </div>
     </div> 
     <?php endwhile; 
     wp_reset_postdata();
     else : ?>
     <p><?php _e( 'Empty.' ); ?></p>
     <?php endif; ?>

is working only when I remove

this 'post_count'=>'2'

important instruction.

What am I doing wrong?
I will be grateful for your help

Read more here: wordpress loop with two statement


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: