rewind_posts()

Rewind the loop posts.

Source

function rewind_posts() {
	global $wp_query;

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

	$wp_query->rewind_posts();
}

Changelog

VersionDescription
1.5.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    Example with custom query migrated from Codex

    <?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; ?>

You must log in before being able to contribute a note or feedback.