[wp-trac] [WordPress Trac] #56992: The Loop displays incorrect data for queries started with `fields => 'id=>parent'`.

WordPress Trac noreply at wordpress.org
Thu Feb 27 01:08:53 UTC 2025


#56992: The Loop displays incorrect data for queries started with `fields =>
'id=>parent'`.
-------------------------------------------------+-------------------------
 Reporter:  peterwilsoncc                        |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  6.8
Component:  Query                                |     Version:  3.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests dev-        |     Focuses:
  feedback 2nd-opinion                           |
-------------------------------------------------+-------------------------

Comment (by peterwilsoncc):

 @SirLouen It's always possible I am not explaining well :)

 > But theoretically, with 'id=>parent' you are just saying that it returns
 an associative array of post IDs and their parent IDs not the whole data.
 In $global_post we should only find that, right?

 That limited set of data is accessible via `$query->posts` without the
 need to start the loop. My reading of how `WP_Query` is used is that it's
 expected that data is populated with the sub-set when the `fields`
 parameter is provided.

 When in the loop, it's expected that the functions `get_the_title()`,
 `get_the_content()` and a large number of others return the respective
 data for the the global post object (ie, calling the functions without
 specifying a post ID).

 My expectation once I start the loop by calling `::the_post()` is that the
 global post will always contain the complete set of post data and that
 calling `get_post()` and `get_post( $current_global_post_id )` return the
 same thing.

 I'm working on a PR and pushing some tests to hopefully demonstrate what I
 see as the problem.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56992#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list