Codex

Function Reference/wp reset postdata

Contents

Description

After looping through a separate query, this function restores the $post global to the current post in the main query.

Usage

<?php wp_reset_postdata(); ?>

Parameters

This function does not accept any parameters.

Return Values

This function does not return any values.

Examples

$original_query = $wp_query;
$wp_query = null;
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
	while ( have_posts() ) : the_post();
		the_title();
		the_excerpt();
	endwhile;
else:
	echo 'no posts found';
endif;
$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();

Notes

  • Uses: $wp_query

Change Log

Source File

wp_reset_postdata() is located in wp-includes/query.php.

Related

Query Tags: WP_Query (Class), get_query_var(), query_posts(), have posts(), the_post(), rewind_posts(), wp_reset_postdata(), wp_reset_query()

See also index of Function Reference and index of Template Tags.