Introduce wp_reset_postdata(). Use it to reset the post global for the current query_posts() call after using a loop with a new WP_Query object. Fixes #12320 props scribu.
git-svn-id: http://svn.automattic.com/wordpress/trunk@14607 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
742db4bc22
commit
08fc51b214
|
@ -554,7 +554,9 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
|||
</ul>
|
||||
<?php echo $after_widget; ?>
|
||||
<?php
|
||||
wp_reset_query(); // Restore global post data stomped by the_post().
|
||||
// Reset the global $the_post as this query will have stomped on it
|
||||
wp_reset_postdata();
|
||||
|
||||
endif;
|
||||
|
||||
$cache[$args['widget_id']] = ob_get_flush();
|
||||
|
|
|
@ -75,6 +75,17 @@ function &query_posts($query) {
|
|||
function wp_reset_query() {
|
||||
unset($GLOBALS['wp_query']);
|
||||
$GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
/**
|
||||
* After looping through a separate query, this function restores
|
||||
* 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;
|
||||
|
|
Loading…
Reference in New Issue