WP_Query::reset_postdata()publicWP 3.7.0

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

Method of the class: WP_Query{}

No Hooks.

Return

null. Nothing (null).

Usage

global $wp_query;
$wp_query->reset_postdata();

Notes

  • Global. WP_Post. $post Global post object.

Changelog

Since 3.7.0 Introduced.

WP_Query::reset_postdata() code WP 6.5.2

public function reset_postdata() {
	if ( ! empty( $this->post ) ) {
		$GLOBALS['post'] = $this->post;
		$this->setup_postdata( $this->post );
	}
}