Make WordPress Core


Ignore:
Timestamp:
09/12/2015 08:57:06 PM (9 years ago)
Author:
boonebgorges
Message:

Allow setup_postdata() to accept a post ID.

Previously, it accepted only a full post object.

Props sc0ttclark, mordauk, wonderboymusic.
Fixes #30970.

File:
1 edited

Legend:

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

    r34073 r34089  
    46174617     *
    46184618     * @since 4.1.0
     4619     * @since 4.4.0 Added the ability to pass a post ID to `$post`.
    46194620     *
    46204621     * @global int             $id
     
    46284629     * @global int             $numpages
    46294630     *
    4630      * @param WP_Post $post Post data.
     4631     * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
    46314632     * @return true True when finished.
    46324633     */
    46334634    public function setup_postdata( $post ) {
    46344635        global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
     4636
     4637        if ( ! ( $post instanceof WP_Post ) ) {
     4638            $post = get_post( $post );
     4639        }
     4640
     4641        if ( ! $post ) {
     4642            return;
     4643        }
    46354644
    46364645        $id = (int) $post->ID;
     
    47024711        if ( ! empty( $this->post ) ) {
    47034712            $GLOBALS['post'] = $this->post;
    4704             setup_postdata( $this->post );
     4713            $this->setup_postdata( $this->post );
    47054714        }
    47064715    }
     
    47704779 *
    47714780 * @since 1.5.0
     4781 * @since 4.4.0 Added the ability to pass a post ID to `$post`.
    47724782 *
    47734783 * @global WP_Query $wp_query
    47744784 *
    4775  * @param object $post Post data.
     4785 * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
    47764786 * @return bool True when finished.
    47774787 */
Note: See TracChangeset for help on using the changeset viewer.