Make WordPress Core

Changeset 14607


Ignore:
Timestamp:
05/13/2010 08:39:54 PM (14 years ago)
Author:
westi
Message:

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.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-widgets.php

    r14486 r14607  
    555555        <?php echo $after_widget; ?>
    556556<?php
    557             wp_reset_query();  // Restore global post data stomped by the_post().
     557        // Reset the global $the_post as this query will have stomped on it
     558        wp_reset_postdata();
     559
    558560        endif;
    559561
  • trunk/wp-includes/query.php

    r14603 r14607  
    7676    unset($GLOBALS['wp_query']);
    7777    $GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];
     78    wp_reset_postdata();
     79}
     80
     81/**
     82 * After looping through a separate query, this function restores
     83 * the $post global to the current post in the main query
     84 *
     85 * @since 3.0.0
     86 * @uses $wp_query
     87 */
     88function wp_reset_postdata() {
    7889    global $wp_query;
    7990    if ( !empty($wp_query->post) ) {
Note: See TracChangeset for help on using the changeset viewer.