WP_Query::setup_postdata()publicWP 4.1.0

Sets up global post data.

Method of the class: WP_Query{}

Hooks from the method

Return

true. True when finished.

Usage

global $wp_query;
$wp_query->setup_postdata( $post );
$post(WP_Post|object|int) (required)
WP_Post instance or Post ID/object.

Notes

  • Global. Int. $id
  • Global. WP_User. $authordata
  • Global. String. $currentday
  • Global. String. $currentmonth
  • Global. Int. $page
  • Global. Array. $pages
  • Global. Int. $multipage
  • Global. Int. $more
  • Global. Int. $numpages

Changelog

Since 4.1.0 Introduced.
Since 4.4.0 Added the ability to pass a post ID to $post.

WP_Query::setup_postdata() code WP 6.5.2

public function setup_postdata( $post ) {
	global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;

	if ( ! ( $post instanceof WP_Post ) ) {
		$post = get_post( $post );
	}

	if ( ! $post ) {
		return;
	}

	$elements = $this->generate_postdata( $post );
	if ( false === $elements ) {
		return;
	}

	$id           = $elements['id'];
	$authordata   = $elements['authordata'];
	$currentday   = $elements['currentday'];
	$currentmonth = $elements['currentmonth'];
	$page         = $elements['page'];
	$pages        = $elements['pages'];
	$multipage    = $elements['multipage'];
	$more         = $elements['more'];
	$numpages     = $elements['numpages'];

	/**
	 * Fires once the post data has been set up.
	 *
	 * @since 2.8.0
	 * @since 4.1.0 Introduced `$query` parameter.
	 *
	 * @param WP_Post  $post  The Post object (passed by reference).
	 * @param WP_Query $query The current Query object (passed by reference).
	 */
	do_action_ref_array( 'the_post', array( &$post, &$this ) );

	return true;
}