Changeset 59919
- Timestamp:
- 03/03/2025 09:43:44 PM (14 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
-
src/wp-includes/class-wp-query.php (modified) (2 diffs)
-
tests/phpunit/tests/query/cacheResults.php (modified) (2 diffs)
-
tests/phpunit/tests/query/thePost.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r59796 r59919 3739 3739 3740 3740 if ( ! $this->in_the_loop ) { 3741 // Only prime the post cache for queries limited to the ID field. 3742 $post_ids = array_filter( $this->posts, 'is_numeric' ); 3743 // Exclude any falsey values, such as 0. 3744 $post_ids = array_filter( $post_ids ); 3741 // Get post IDs to prime incomplete post objects. 3742 $post_ids = array_reduce( 3743 $this->posts, 3744 function ( $carry, $post ) { 3745 if ( is_numeric( $post ) && $post > 0 ) { 3746 // Query for post ID. 3747 $carry[] = $post; 3748 } 3749 3750 if ( is_object( $post ) && isset( $post->ID ) ) { 3751 // Query for object, either WP_Post or stdClass. 3752 $carry[] = $post->ID; 3753 } 3754 3755 return $carry; 3756 }, 3757 array() 3758 ); 3745 3759 if ( $post_ids ) { 3746 3760 _prime_post_caches( $post_ids, $this->query_vars['update_post_term_cache'], $this->query_vars['update_post_meta_cache'] ); 3747 3761 } 3748 $post_objects = array_map( 'get_post', $ this->posts );3762 $post_objects = array_map( 'get_post', $post_ids ); 3749 3763 update_post_author_caches( $post_objects ); 3750 3764 } … … 3765 3779 3766 3780 $post = $this->next_post(); 3781 3782 // Get the post ID. 3783 if ( is_object( $post ) ) { 3784 $global_post_id = $post->ID; 3785 } else { 3786 $global_post_id = $post; 3787 } 3788 3789 // Ensure the global $post is the full post object. 3790 $post = get_post( $global_post_id ); 3767 3791 $this->setup_postdata( $post ); 3768 3792 } -
trunk/tests/phpunit/tests/query/cacheResults.php
r59766 r59919 1926 1926 * @since 6.1.1 1927 1927 * @ticket 56948 1928 * @ticket 56992 1928 1929 * 1929 1930 * @covers WP_Query::the_post … … 1979 1980 public function data_author_cache_warmed_by_the_loop() { 1980 1981 return array( 1981 'fields: empty' => array( '' ), 1982 'fields: all' => array( 'all' ), 1983 'fields: ids' => array( 'ids' ), 1984 /* 1985 * `id=>parent` is untested pending the resolution of an existing bug. 1986 * See https://core.trac.wordpress.org/ticket/56992 1987 */ 1982 'fields: empty' => array( '' ), 1983 'fields: all' => array( 'all' ), 1984 'fields: ids' => array( 'ids' ), 1985 'fields: id=>parent' => array( 'id=>parent' ), 1988 1986 ); 1989 1987 }
Note: See TracChangeset
for help on using the changeset viewer.