posts_per_page returns one extra post

I want to get latest two posts. I’m trying to use following query, but for some strange reasons it is returning me one extra post (total 3 posts instead of 2). Similarly if i put 3 in the query, it will return 4 posts.
Why this is happening and how can I fix it? Thanks.

<?php query_posts( 'posts_per_page=2' ); ?>
    <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
            <?php the_title(); ?>                       
        <?php endwhile; endif;?>
    <?php wp_reset_query();?>

Related posts

Leave a Reply

1 comment

  1. Do this:

    <?php $my_query = new WP_Query('category_name=mycatname&showposts=2'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <?php the_title(); ?>
    
    <?php endwhile; ?>
    

    No need for wp_reset_query; this loop can be used multiple times in a template.

    Delete the category_name=mycatname& if you don’t need the category name.