Title: rewind_posts after query_posts ?
Last modified: August 19, 2016

---

# rewind_posts after query_posts ?

 *  Resolved [volfro](https://wordpress.org/support/users/volfro/)
 * (@volfro)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/rewind_posts-after-query_posts/)
 * Hey all,
 * I’m trying to use a loop and query_posts to grab content from a certain page,
   then rewind_posts to display the rest of the content normally.
 * It’s an extra section in my header.php:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post();
       	$values = get_post_custom_values("Page Description");
       endwhile; endif; ?>
   
       	<?php if ($values[0]) : echo $values[0];
       	else :
       		query_posts('pagename=default-description');
       		if (have_posts()) : while (have_posts()) : the_post();
       			the_content();
       		endwhile; endif;
   
       	endif; rewind_posts(); ?>
       ```
   
 * But rewind_posts isn’t actually doing anything. The if statement works as expected,
   but if I’m on a page that doesn’t have anything in Page Description, it calls
   the default-description page where it’s supposed to AND for every other loop 
   on the page.
 * Why? I thought rewind_posts was supposed to reset the WP_query…
 * Any help is greatly, greatly appreciated.

Viewing 1 replies (of 1 total)

 *  Thread Starter [volfro](https://wordpress.org/support/users/volfro/)
 * (@volfro)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/rewind_posts-after-query_posts/#post-673478)
 * Leave it to the Codex. I’d thought I’d read The Loop section enough to make my
   eyes fall out, but I guess I didn’t read carefully enough.
 * Created a custom query:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post();
       	$values = get_post_custom_values("Page Description");
       endwhile; endif; ?>
   
       	<?php if ($values[0]) : echo $values[0];
       	else :
       		$default_description = new WP_Query('pagename=default-description');
       		while ($default_description -> have_posts()) : $default_description -> the_post();
       			the_content();
       		endwhile;
       	endif; ?>
       ```
   
 * …and did a `rewind_posts()` at the end of header.php.
 * This solves my problem (I’m avoiding the use of plugins like Improved Include
   Page for this particular client), but I’m a little confused by the Codex’s description
   of _why_ specifically query_posts, placed above the main loop, still affects 
   the main loop, even after I do a rewind_posts. Any WP gurus care to explain?
 * My PHP knowledge is limited to understanding of WP templates, so layman’s terms
   help here. Thanks again.

Viewing 1 replies (of 1 total)

The topic ‘rewind_posts after query_posts ?’ is closed to new replies.

## Tags

 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [rewind_posts()](https://wordpress.org/support/topic-tag/rewind_posts/)
 * [the-loop](https://wordpress.org/support/topic-tag/the-loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [volfro](https://wordpress.org/support/users/volfro/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/rewind_posts-after-query_posts/#post-673478)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
