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

WordPress Trac noreply at wordpress.org
Mon Mar 10 22:53:24 UTC 2025


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

Comment (by peterwilsoncc):

 @SirLouen

 The issue is that the global post is only partially populated when the
 fields are set to `id=>parent`. If you call `WP_Query()` with the fields
 parameter set to `id` or `all`, the global post is populated correctly.

 If it just affected `global $post`, I might be fine with that but it
 affects all the functions that are documented to the effect that "within
 the loop, this function will return the value of the [thing] of the global
 post" This includes:

 * `get_the_content()`
 * `get_the_excerpt()`
 * `get_the_title()`
 * `get_the_time()`
 * most other functions used in the loop and prefixed `get_` or `the_`

 I understand your concern but I can't be convinced that these functions
 should return incorrect data within the loop for one of the three `fields`
 parameters but not the others. The return value for each was empty.

 This is a real world case as [https://github.com/WordPress/wordpress-
 develop/blob/1cd5c21c43ccb82165d76e59fc062cb56b5d04d2/tests/phpunit/tests/query/thePost.php#L78-L80
 these assertions] were failing prior to this change for the `id=>parent`
 fields parameter but neither of the others.

 ----

 I'm leaving this ticket open to review the performance issues you raise.

 For `id=>parent` some performance impact is expected when starting the
 loop, as the post object are now queried to ensure the functions above
 return the correct data.

 If accessing the parent child relationships via `WP_Query::$posts` no
 impact is expected as the full post objects will not be queried.

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


More information about the wp-trac mailing list