WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The incomplete Codex about this, says very simply:

Rewind the loop posts.

As per this WPSE thread, with Eugene Manuilov's answer, I got:

// fetch first post from the loop

// get post type
$post_type = get_post_type(); 

// rewind the loop posts

With Ian Stewart's theme development tutorial, I found rewind_posts()'s use in archive.php, category.php, tag.php, author.php:

<?php the_post(); ?>
<!-- echo page title -->
<?php rewind_posts(); ?>
<?php while ( have_posts() ) : the_post(); ?>
   <!-- echo content -->
<?php endwhile; ?>

But in TwentyThirteen theme we can't see something like this, but a simple WordPress loop with conditional:

<?php if ( have_posts() ) : ?>
<!-- echo page title -->
<?php while ( have_posts() ) : the_post(); ?>
   <!-- echo content -->
<?php endwhile; ?>
<?php endif; ?>

So, I just want to know, while I have the WordPress loop to use, and that works with pagination also, then where do I need to REWIND THE LOOP, and why?


Ok, after the first answer, I got a very good article describing the 3 Query-reset functions in WordPress:

» 3 Ways to Reset the WordPress Loop by Jeff Starr - DigWP.com

I hope with this the answer can be a lot more educative than currently what we got.

share|improve this question
Please summon the digwp article in your own answer. I really hoped for a much more interesting and educational answer than what we got so far. – kaiser Oct 24 '13 at 4:15
up vote 4 down vote accepted

It generally the clears the current loop

// main loop
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>

// rewind
<?php rewind_posts(); ?>

// new loop
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>

Here it clears the main loop and start with the new loop

Reference: http://codex.wordpress.org/Function_Reference/rewind_posts

share|improve this answer
Some notes: It's not necessary to open and close PHP tags on every line. You might also want to close the if/endif at the end. Else you'd trigger the second loop no matter if there're posts or not. Last: Please use the WYSIWYG editor to format your contents. – kaiser Oct 23 '13 at 17:43
Ok. Marked this one as accepted because I found this digwp post helpful with the help of this answer. Thanks. – Mayeenul Islam Oct 23 '13 at 18:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.