diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index e7ad0a0f72..a62d05e3e2 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -3738,14 +3738,28 @@ class WP_Query { global $post; if ( ! $this->in_the_loop ) { - // Only prime the post cache for queries limited to the ID field. - $post_ids = array_filter( $this->posts, 'is_numeric' ); - // Exclude any falsey values, such as 0. - $post_ids = array_filter( $post_ids ); + // Get post IDs to prime incomplete post objects. + $post_ids = array_reduce( + $this->posts, + function ( $carry, $post ) { + if ( is_numeric( $post ) && $post > 0 ) { + // Query for post ID. + $carry[] = $post; + } + + if ( is_object( $post ) && isset( $post->ID ) ) { + // Query for object, either WP_Post or stdClass. + $carry[] = $post->ID; + } + + return $carry; + }, + array() + ); if ( $post_ids ) { _prime_post_caches( $post_ids, $this->query_vars['update_post_term_cache'], $this->query_vars['update_post_meta_cache'] ); } - $post_objects = array_map( 'get_post', $this->posts ); + $post_objects = array_map( 'get_post', $post_ids ); update_post_author_caches( $post_objects ); } @@ -3764,6 +3778,16 @@ class WP_Query { } $post = $this->next_post(); + + // Get the post ID. + if ( is_object( $post ) ) { + $global_post_id = $post->ID; + } else { + $global_post_id = $post; + } + + // Ensure the global $post is the full post object. + $post = get_post( $global_post_id ); $this->setup_postdata( $post ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index dbf6972d33..ca34392fbd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59918'; +$wp_version = '6.8-alpha-59919'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.