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 ); } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.7.0 | Introduced. |