Title: rewind_posts
Published: April 25, 2014
Last modified: February 24, 2026

---

# rewind_posts()

## In this article

 * [Source](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#wp--skip-link--target)

Rewind the loop posts.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#source)󠁿

    ```php
    function rewind_posts() {
    	global $wp_query;

    	if ( ! isset( $wp_query ) ) {
    		return;
    	}

    	$wp_query->rewind_posts();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/query.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/query.php#L981)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/query.php#L981-L989)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Query::rewind_posts()](https://developer.wordpress.org/reference/classes/wp_query/rewind_posts/)`wp-includes/class-wp-query.php` |

Rewinds the posts and resets post index.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#comment-content-1055)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/rewind_posts/#comment-1055)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frewind_posts%2F%23comment-1055)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frewind_posts%2F%23comment-1055)
 4.  **Basic Example**
 5.      ```php
         // 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; ?>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frewind_posts%2F%3Freplytocom%3D1055%23feedback-editor-1055)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/rewind_posts/?output_format=md#comment-content-3351)
 8.    [leogermani](https://profiles.wordpress.org/leogermani/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/rewind_posts/#comment-3351)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frewind_posts%2F%23comment-3351)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frewind_posts%2F%23comment-3351)
 10. Example with custom query migrated from Codex
 11.     ```php
         <?php 
         $args = array( 'posts_per_page' => -1 );
         $my_posts = new WP_Query($args);
         if ($my_posts->have_posts()) : while ($my_posts->have_posts()) : $my_posts->the_post(); ?>
         <?php the_content(); ?>
         <?php endwhile; endif; ?>
     
         // rewind
         <?php $my_posts->rewind_posts(); ?>
     
         // new loop
         <?php while ($my_posts->have_posts()) : $my_posts->the_post(); ?>
         <?php the_content(); ?>
         <?php endwhile; ?>
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frewind_posts%2F%3Freplytocom%3D3351%23feedback-editor-3351)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frewind_posts%2F)
before being able to contribute a note or feedback.