Codex tools: Log in
Contents |
After looping through a separate query, this function restores the $post global to the current post in the main query.
<?php wp_reset_postdata(); ?>
This function does not accept any parameters.
This function does not return any values.
$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();
wp_reset_postdata() is located in wp-includes/query.php.
Query Tags: WP_Query (Class), get_query_var(), query_posts(), have posts(), the_post(), rewind_posts(), wp_reset_postdata(), wp_reset_query()