Make WordPress Core


Ignore:
Timestamp:
09/24/2013 03:52:41 PM (11 years ago)
Author:
nacin
Message:

Introduce a reset_postdata() method on the WP_Query object, which wp_reset_postdata() now wraps.

props ericlewis.
fixes #24785.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r25312 r25601  
    109109/**
    110110 * After looping through a separate query, this function restores
    111  * the $post global to the current post in the main query
     111 * the $post global to the current post in the main query.
    112112 *
    113113 * @since 3.0.0
     
    116116function wp_reset_postdata() {
    117117    global $wp_query;
    118     if ( !empty($wp_query->post) ) {
    119         $GLOBALS['post'] = $wp_query->post;
    120         setup_postdata($wp_query->post);
    121     }
     118    $wp_query->reset_postdata();
    122119}
    123120
     
    36293626        return $wp_the_query === $this;
    36303627    }
     3628
     3629    /**
     3630     * After looping through a nested query, this function
     3631     * restores the $post global to the current post in this query.
     3632     *
     3633     * @since 3.7.0
     3634     *
     3635     * @return bool
     3636     */
     3637    function reset_postdata() {
     3638        if ( ! empty( $this->post ) ) {
     3639            $GLOBALS['post'] = $this->post;
     3640            setup_postdata( $this->post );
     3641        }
     3642    }
    36313643}
    36323644
Note: See TracChangeset for help on using the changeset viewer.