Title: Looping the Loop
Last modified: August 18, 2016

---

# Looping the Loop

 *  [Root](https://wordpress.org/support/users/root/)
 * (@root)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/looping-the-loop/)
 * I have got my loop repeating but not in a way that is useful. As I want to run
   different queries in both loops presumably I need to swap the global variable
   as per Alexs stuff in Codex. But how is it put together ?. On loop 1; I am trying
   to get single post from a single cat and on loop 2;- 5 posts say from another
   single cat ? All code or prompts / hints gratefully received. TY.

Viewing 1 replies (of 1 total)

 *  [ifelse](https://wordpress.org/support/users/ifelse/)
 * (@ifelse)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/looping-the-loop/#post-177404)
 * You can try this;
 * on the first loop, do as you would normally. On the second loop however, you 
   create a new WP_Query object (which is what handles the actions and properties
   for the_loop) via:
    `<?php $sub_query = new WP_Query('category_name=site&showposts
   =5'); ?>`
 * Now you can loop through this wp_query object as you would normally:
    `<?php 
   while ($sub_query->have_posts()) : $sub_query->the_post(); ?> <?php  the_excerpt();?
   > <?php endwhile; ?>

Viewing 1 replies (of 1 total)

The topic ‘Looping the Loop’ is closed to new replies.

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [ifelse](https://wordpress.org/support/users/ifelse/)
 * Last activity: [21 years, 1 month ago](https://wordpress.org/support/topic/looping-the-loop/#post-177404)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
