Title: Multiple Loops problem
Last modified: August 19, 2016

---

# Multiple Loops problem

 *  Resolved [yamtunbo](https://wordpress.org/support/users/yamtunbo/)
 * (@yamtunbo)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/multiple-loops-problem-2-2/)
 * Howdy
 * What I’m trying to do is add a list of links to posts in a specific category 
   at the bottom of all the posts that are in that specific category.
 * I’m editing single.php to try and do this. Here’s the code I’m using:
 *     ```
       if (in_category(643)) {
               $myQuery = new WP_Query('category_name=f22');
               echo "Here's the links to the other images in this project ...";
               echo '<ul style="margin-left: 30px">';
               while ($myQuery->have_posts()) : $myQuery->the_post();
                       $tempID = get_the_ID();
                       echo '<li><a href="/blog/index.php?p='.$tempID.'">';
                       echo the_title();
                       echo '</a></il>';
               endwhile;
               echo '</ul>';
       }
       ```
   
 * This code lists the links to the posts in the category fine; the problem I’m 
   having is that once the loop has finished, the rest of the post thinks that it’s
   the first post in the category rather than the post that it started out being
   before I started looping out links to the other posts in the category. If that
   makes sense.
 * Here you can see what I mean – the first post in the category ‘f22’ on my photoblog
   was posted on the 8th Jan, you can see it here:
 * [http://chris-beaumont.com/blog/index.php?p=847](http://chris-beaumont.com/blog/index.php?p=847)
 * Then if you look at all the other posts in the same ‘f22’ category, you can see
   that they all appear to have been posted on the 8th Jan, and have all the same
   metadata, even though they weren’t posted on the 8th Jan, and don’t have the 
   same metadata:
 * [http://chris-beaumont.com/blog/index.php?p=959](http://chris-beaumont.com/blog/index.php?p=959)
   
   [http://chris-beaumont.com/blog/index.php?p=969](http://chris-beaumont.com/blog/index.php?p=969)
   [http://chris-beaumont.com/blog/index.php?p=977](http://chris-beaumont.com/blog/index.php?p=977)
 * They also have the same ‘Test Comment’ at the bottom of every page, even though
   the ‘Test Comment’ has only been posted on the first post in the category. This
   is because the date, all the meta data, and the comments, are all rendered out
   of single.php after the code loop I’ve put in to list links to the other posts
   in the category.
 * So my question is – how the conk do I stop the loop that I put into single.php
   from affecting the code that comes after it? I’ve tried all the methods that 
   are listed on this page [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop)
   regarding Multiple Loops, but nothing seems to work.
 * Any help is much appreciated.

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/multiple-loops-problem-2-2/#post-1367255)
 * Use wp_reset_query after your ‘custom’ query loop
 *     ```
       <?php
       wp_reset_query();
       ?>
       ```
   
 *  Thread Starter [yamtunbo](https://wordpress.org/support/users/yamtunbo/)
 * (@yamtunbo)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/multiple-loops-problem-2-2/#post-1367269)
 * Beautiful … thank you very much.

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

The topic ‘Multiple Loops problem’ is closed to new replies.

## Tags

 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)
 * [single.php](https://wordpress.org/support/topic-tag/single-php/)

 * 2 replies
 * 2 participants
 * Last reply from: [yamtunbo](https://wordpress.org/support/users/yamtunbo/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/multiple-loops-problem-2-2/#post-1367269)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
