setup_postdata

The timeline below displays how wordpress function setup_postdata has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.3

/**
 * Set up global post data.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability to pass a post ID to `$post`.
 *
 * @global WP_Query $wp_query WordPress Query object.
 *
 * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
 * @return bool True when finished.
 */
function setup_postdata($post)
{
    global $wp_query;
    if (!empty($wp_query) && $wp_query instanceof WP_Query) {
        return $wp_query->setup_postdata($post);
    }
    return false;
}

WordPress Version: 4.4

/**
 * Set up global post data.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability to pass a post ID to `$post`.
 *
 * @global WP_Query $wp_query Global WP_Query instance.
 *
 * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
 * @return bool True when finished.
 */
function setup_postdata($post)
{
    global $wp_query;
    if (!empty($wp_query) && $wp_query instanceof WP_Query) {
        return $wp_query->setup_postdata($post);
    }
    return false;
}

WordPress Version: 4.3

/**
 * Set up global post data.
 *
 * @since 1.5.0
 *
 * @global WP_Query $wp_query
 *
 * @param object $post Post data.
 * @return bool True when finished.
 */
function setup_postdata($post)
{
    global $wp_query;
    if (!empty($wp_query) && $wp_query instanceof WP_Query) {
        return $wp_query->setup_postdata($post);
    }
    return false;
}

WordPress Version: 4.1

/**
 * Set up global post data.
 *
 * @since 1.5.0
 *
 * @param object $post Post data.
 * @return bool True when finished.
 */
function setup_postdata($post)
{
    global $wp_query;
    if (!empty($wp_query) && $wp_query instanceof WP_Query) {
        return $wp_query->setup_postdata($post);
    }
    return false;
}

WordPress Version: 3.9

/**
 * Set up global post data.
 *
 * @since 1.5.0
 *
 * @param object $post Post data.
 * @uses do_action_ref_array() Calls 'the_post'
 * @return bool True when finished.
 */
function setup_postdata($post)
{
    global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
    $id = (int) $post->ID;
    $authordata = get_userdata($post->post_author);
    $currentday = mysql2date('d.m.y', $post->post_date, false);
    $currentmonth = mysql2date('m', $post->post_date, false);
    $numpages = 1;
    $multipage = 0;
    $page = get_query_var('page');
    if (!$page) {
        $page = 1;
    }
    if (is_single() || is_page() || is_feed()) {
        $more = 1;
    }
    $content = $post->post_content;
    if (false !== strpos($content, '<!--nextpage-->')) {
        if ($page > 1) {
            $more = 1;
        }
        $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
        $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
        $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
        // Ignore nextpage at the beginning of the content.
        if (0 === strpos($content, '<!--nextpage-->')) {
            $content = substr($content, 15);
        }
        $pages = explode('<!--nextpage-->', $content);
        $numpages = count($pages);
        if ($numpages > 1) {
            $multipage = 1;
        }
    } else {
        $pages = array($post->post_content);
    }
    /**
     * Fires once the post data has been setup.
     *
     * @since 2.8.0
     *
     * @param WP_Post &$post The Post object (passed by reference).
     */
    do_action_ref_array('the_post', array(&$post));
    return true;
}

WordPress Version: 3.7

/**
 * Set up global post data.
 *
 * @since 1.5.0
 *
 * @param object $post Post data.
 * @uses do_action_ref_array() Calls 'the_post'
 * @return bool True when finished.
 */
function setup_postdata($post)
{
    global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
    $id = (int) $post->ID;
    $authordata = get_userdata($post->post_author);
    $currentday = mysql2date('d.m.y', $post->post_date, false);
    $currentmonth = mysql2date('m', $post->post_date, false);
    $numpages = 1;
    $multipage = 0;
    $page = get_query_var('page');
    if (!$page) {
        $page = 1;
    }
    if (is_single() || is_page() || is_feed()) {
        $more = 1;
    }
    $content = $post->post_content;
    if (false !== strpos($content, '<!--nextpage-->')) {
        if ($page > 1) {
            $more = 1;
        }
        $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
        $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
        $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
        // Ignore nextpage at the beginning of the content.
        if (0 === strpos($content, '<!--nextpage-->')) {
            $content = substr($content, 15);
        }
        $pages = explode('<!--nextpage-->', $content);
        $numpages = count($pages);
        if ($numpages > 1) {
            $multipage = 1;
        }
    } else {
        $pages = array($post->post_content);
    }
    do_action_ref_array('the_post', array(&$post));
    return true;
}