WP_Query::reset_postdata() WordPress Method

The WP_Query::reset_postdata() method is used to reset the global $post object to the state it was in before any custom query was run. This is useful if you have a custom loop that modifies the global $post object and you want to make sure that the rest of your code is not affected by those changes.

WP_Query::reset_postdata() #

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


Source

File: wp-includes/class-wp-query.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.