WP_Query::generate_postdata( WP_Post|object|int $post ): array|false

In this article

Generates post data.

Parameters

$postWP_Post|object|intrequired
WP_Post instance or Post ID/object.

Return

array|false Elements of post or false on failure.

Source

 *
 * @since 3.1.0
 *
 * @return bool Whether the query is a 404 error.
 */
public function is_404() {
	return (bool) $this->is_404;
}

/**
 * Determines whether the query is for an embedded post.
 *
 * @since 4.4.0
 *
 * @return bool Whether the query is for an embedded post.
 */
public function is_embed() {
	return (bool) $this->is_embed;
}

/**
 * Determines whether the query is the main query.
 *
 * @since 3.3.0
 *
 * @global WP_Query $wp_the_query WordPress Query object.
 *
 * @return bool Whether the query is the main query.
 */
public function is_main_query() {
	global $wp_the_query;
	return $wp_the_query === $this;
}

/**
 * Sets up global post data.
 *
 * @since 4.1.0
 * @since 4.4.0 Added the ability to pass a post ID to `$post`.
 *
 * @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
 *
 * @param WP_Post|object|int $post WP_Post instance or Post ID/object.
 * @return true True when finished.
 */
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;
}

/**

Changelog

VersionDescription
5.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.