Title: Multiple Loop and Comments problem
Last modified: August 19, 2016

---

# Multiple Loop and Comments problem

 *  [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/multiple-loop-and-comments-problem/)
 * I am using code to display a loop within my main loop – before ym comments section.
   It work but the comments are not the comments from my main loop, they are from
   the last item in my loop within the loop. Here is a snippet of my code:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?><div <?php post_class() ?> id="post-<?php the_ID(); ?>">
   
       <?php the_title(); ?>
   
       <div class="storycontent clear music">
       		<?php the_content(__('(more...)')); ?>
   
       <?php if(in_category('20')) { ?>
   
       <h3>Track Listing</h3>
       <ol class="tracks">
       <?php $post_title = get_post_meta($post->ID, 'post_title', $single = true);?>
       <?php $my_query = new WP_Query('category_name='.$post_title.'&order=des&showposts=100');while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate=$post->ID;?>
       <li><?php the_title();?></li>
   
       <?php endwhile; ?>
   
       </ol>
   
       <?php } else { ?>
   
       <?php } ?>     
   
       </div>
   
       <?php comments_template(); // Get wp-comments.php template ?>
       ```
   
 * Any ideas as to why the comments are from the wrong loop?

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

 *  Thread Starter [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/multiple-loop-and-comments-problem/#post-1169964)
 * Please help folks!
 *  Thread Starter [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/multiple-loop-and-comments-problem/#post-1170265)
 * Still stuck here, can’t find any help?
 *  [800a](https://wordpress.org/support/users/800a/)
 * (@800a)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/multiple-loop-and-comments-problem/#post-1170329)
 * You have to reset the second loop within the main loop
 * use this function at the end of second loop:
 * `wp_reset_query()`
 * it works for me 😉
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/multiple-loop-and-comments-problem/#post-1170330)
 * If that does not work, see the Codex page [The Loop](http://codex.wordpress.org/The_Loop),
   especially the section titled ‘Multiple Loops Example 2’.

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

The topic ‘Multiple Loop and Comments problem’ is closed to new replies.

## Tags

 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [multiple](https://wordpress.org/support/topic-tag/multiple/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/multiple-loop-and-comments-problem/#post-1170330)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
