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

---

# Multiple Loops help

 *  [steeler](https://wordpress.org/support/users/steeler/)
 * (@steeler)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/multiple-loops-help-1/)
 * Hi, I have a sidebar before my actual page content that do a wp_query. The question
   is how to reset to the original query of the page so that after that wp_query
   it shows correctly. I.e.
 *     ```
       <?php
       	global $query_string;
       	$temp_string = $query_string;
       	echo $query_string;
       ?>
       <div class="sidebar">
       	<div class="block">
       		<h5>Recent Post</h5>
       		<ul class="recent">
       			<?php
       				$recent = new WP_Query("showposts=7&order=DESC&category_name=Journal");
       				while($recent->have_posts()):
       					$recent->the_post();
       					echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
       				endwhile;
       			?>
       		</ul>
       	</div><!-- end of block -->
       </div><!-- end of sidebar -->
       <?php
       	$query_string = $temp_string;
       	query_posts($query_string);
       ?>
       ```
   
 * and on the content I have:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <?ptp the_title();?>
       <?php endwhile; endif; ?>
       ```
   
 * As you can see i’ve tried saving the query string, but it turns out that the 
   showposts is not saved and it gets the value from the custom wp_query, and there
   is no way for me to know what value I need as the sidebar is used on the single
   posts pages as well as on the archive pages..
 * Can anyone help me out…
 * Thanks beforehand

Viewing 1 replies (of 1 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/multiple-loops-help-1/#post-1518021)
 * After your `endwhile;` use
 *     ```
       wp_reset_query();
       ```
   
 * [Function_Reference/wp_reset_query](http://codex.wordpress.org/Function_Reference/wp_reset_query)

Viewing 1 replies (of 1 total)

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/multiple-loops-help-1/#post-1518021)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
