[wp-trac] [WordPress Trac] #56948: WP_Query::the_post causes a type warning when querying for ids, not full post objects

WordPress Trac noreply at wordpress.org
Thu Nov 3 00:41:42 UTC 2022


#56948: WP_Query::the_post causes a type warning when querying for ids, not full
post objects
--------------------------------------+---------------------
 Reporter:  konyoldeath               |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  6.1.1
Component:  Query                     |     Version:  6.1
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------

Comment (by peterwilsoncc):

 In the [https://github.com/WordPress/wordpress-develop/pull/3553 linked
 pull request]:

 * `WP_Query::the_post()` only attempts to warm the author cache if the
 posts array contains `WP_Post` objects
 * Added a test to ensure the author cache is warmed when returning all
 fields.
 * Added a test to ensure there isn't an error if a subset of fields is
 returned. This uses `assertTrue( true )` as I couldn't find a way to
 `excpectNoError`

 I experimented with warming the cache when a subset of fields was
 requested (either `ids` or `id=>parent`) but it was a little complex with
 the latter as there's no way of knowing whether the developer intends to
 use the posts or the post parents.

 I could be convinced to warm the cache for the post parents as
 `WP_Query::the_post()` will set up the loop using the parent IDs. However,
 that's probably best considered in a ticket for a major release.

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


More information about the wp-trac mailing list