Title: Issue: query_posts displaying extra post
Last modified: August 19, 2016

---

# Issue: query_posts displaying extra post

 *  Resolved [ellp](https://wordpress.org/support/users/ellp/)
 * (@ellp)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/issue-query_posts-displaying-extra-post/)
 * Hello folks!
 * I’m creating one theme for WordPress with multiples Loops inside. The code I’m
   using is someting like that:
 *     ```
       <?php query_posts('showposts=1'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
       <img src="<?php $values = get_post_custom_values("thumbnail"); echo $values[0]; ?>" width="148" height="120" alt="<?php the_title()?>" />					
   
        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
   
       <?php endwhile; else: ?>
       <?php endif; wp_reset_query(); ?>
       ```
   
 * But, the output **is aways the result +1 extra post**. For exemple: in this code
   above, display 2 posts, but I want only one.
 * Another one:
 *     ```
       <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar_page_1') ) : ?>
       		<h3>Latest Reviews</h3>
   
       		<?php $my_query = new WP_Query('showposts=3');
       		  while ($my_query->have_posts()) : $my_query->the_post();?>
       				    <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
       		  <?php endwhile; ?>
   
       	<?php endif;?>
       ```
   
 * This code above output is 4 posts, but I want only 3.
 * I’m using starkers theme as basic framework.
 * Question: Its a bug or I’m doing something wrong? Any ideas to solve that?
 * Thanks! And sorry about my english :/

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/issue-query_posts-displaying-extra-post/#post-1276718)
 * Try replacing `showposts` with `posts_per_page`. If that doesn’t work, it could
   be something higher up that’s causing you problems.
 * You might also want to look at using get_posts instead of query_posts – especially
   in that second loop since you’re only using the the_permalink and the_title (
   both of which should be available via get_posts).
 *  Thread Starter [ellp](https://wordpress.org/support/users/ellp/)
 * (@ellp)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/issue-query_posts-displaying-extra-post/#post-1276742)
 * Hello esmi!
 * I have tried to use post_per_page too, but I got the same error. About your second
   idea I will try that. Thanks.
 *  Thread Starter [ellp](https://wordpress.org/support/users/ellp/)
 * (@ellp)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/issue-query_posts-displaying-extra-post/#post-1276771)
 * Hello again esmi!
 * I’ve used your tip to solve this issue, and work like a charm! I used a code 
   like:
 *     ```
       <?php
       		$lastposts = get_posts('numberposts=5');
       		foreach($lastposts as $post) :
       		setup_postdata($post);
       		?>
       		<h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2>
   
       		<?php endforeach; ?>
       ```
   
 * Thank You! 😀

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Issue: query_posts displaying extra post’ is closed to new replies.

## Tags

 * [extra](https://wordpress.org/support/topic-tag/extra/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [ellp](https://wordpress.org/support/users/ellp/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/issue-query_posts-displaying-extra-post/#post-1276771)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
