Introduce a reset_postdata() method on the WP_Query object, which wp_reset_postdata() now wraps.
props ericlewis. fixes #24785. Built from https://develop.svn.wordpress.org/trunk@25601 git-svn-id: http://core.svn.wordpress.org/trunk@25518 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
26193b684b
commit
1fda14e76b
|
@ -108,17 +108,14 @@ function wp_reset_query() {
|
|||
|
||||
/**
|
||||
* After looping through a separate query, this function restores
|
||||
* the $post global to the current post in the main query
|
||||
* the $post global to the current post in the main query.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @uses $wp_query
|
||||
*/
|
||||
function wp_reset_postdata() {
|
||||
global $wp_query;
|
||||
if ( !empty($wp_query->post) ) {
|
||||
$GLOBALS['post'] = $wp_query->post;
|
||||
setup_postdata($wp_query->post);
|
||||
}
|
||||
$wp_query->reset_postdata();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3628,6 +3625,21 @@ class WP_Query {
|
|||
global $wp_the_query;
|
||||
return $wp_the_query === $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* After looping through a nested query, this function
|
||||
* restores the $post global to the current post in this query.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function reset_postdata() {
|
||||
if ( ! empty( $this->post ) ) {
|
||||
$GLOBALS['post'] = $this->post;
|
||||
setup_postdata( $this->post );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue