Title: Double Loop causing incorrect comment count
Last modified: August 19, 2016

---

# Double Loop causing incorrect comment count

 *  [shaolintiger](https://wordpress.org/support/users/shaolintiger/)
 * (@shaolintiger)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/double-loop-causing-incorrect-comment-count/)
 * The site is over here: [http://www.thenutgraph.com/](http://www.thenutgraph.com/)
 * Anyway the issue I’m having is on the front page, within the boxes I want the
   latest 2 posts from the same category below the excerpt.
 * I had it working fine with wp_get_archives – but the issue with that is the function
   doesn’t support any kind of offset, so it was showing duplicate posts (like it’d
   show the same post that was already featured in the box + 1 more).
 * So I changed it to use query_posts, but then as it was already inside a loop 
   it it messed up the last section of the box – the comment count and link were
   from the 2nd post in the list not the featured post.
 * So now I’ve changed it again to temporarily store $post and replace it back after
   it’s done, now the link is correct but it’s still showing the comment count for
   the 2nd listed post rather than the featured post – and I really can’t work out
   why!
 * Any help is appreciated, here’s the code:
 *     ```
       <?php
       global $post;
       $tmp_post = $post;
       $myposts = get_posts('numberposts=2&offset=2&category='.$category_id.'');
       foreach($myposts as $post) :
       setup_postdata($post);
       ?>
       "><?php the_title(); ?>
   
       <?php endforeach; ?>
       <?php $post = $tmp_post; ?>
       ```
   

The topic ‘Double Loop causing incorrect comment count’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [shaolintiger](https://wordpress.org/support/users/shaolintiger/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/double-loop-causing-incorrect-comment-count/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
