Make WordPress Core

Ticket #12320: 12320.2.diff

File 12320.2.diff, 1.1 KB (added by scribu, 15 years ago)

introduce wp_reset_postdata()

  • wp-includes/default-widgets.php

     
    554554                </ul>
    555555                <?php echo $after_widget; ?>
    556556<?php
    557                         wp_reset_query();  // Restore global post data stomped by the_post().
     557                wp_reset_postdata();
     558
    558559                endif;
    559560
    560561                $cache[$args['widget_id']] = ob_get_flush();
  • wp-includes/query.php

     
    7575function wp_reset_query() {
    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 last 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) ) {
    8091                $GLOBALS['post'] = $wp_query->post;