Make WordPress Core


Ignore:
Timestamp:
11/09/2022 12:57:02 AM (16 months ago)
Author:
peterwilsoncc
Message:

Query: Prevent ID only queries erroring when starting the loop.

Ensure only full post objects are passed to update_post_author_caches() when called within WP_Query::the_post(). This prevents an error when starting the Loop for Queries initiated with a subset of fields or IDs only.

Props konyoldeath, dd32, lozula, TimothyBlynJacobs, spacedmonkey, mxbclang, peterwilsoncc.
Fixes #56948.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r54768 r54771  
    35873587
    35883588        if ( ! $this->in_the_loop ) {
    3589             update_post_author_caches( $this->posts );
     3589            // Only prime the post cache for queries limited to the ID field.
     3590            $post_ids = array_filter( $this->posts, 'is_numeric' );
     3591            // Exclude any falsey values, such as 0.
     3592            $post_ids = array_filter( $post_ids );
     3593            if ( $post_ids ) {
     3594                _prime_post_caches( $post_ids, $this->query_vars['update_post_term_cache'], $this->query_vars['update_post_meta_cache'] );
     3595            }
     3596            $post_objects = array_map( 'get_post', $this->posts );
     3597            update_post_author_caches( $post_objects );
    35903598        }
    35913599
Note: See TracChangeset for help on using the changeset viewer.