Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#44221 closed defect (bug) (fixed)

`get_terms()` with `all_with_object_id` returns cached `stdClass` objects

Reported by: dlh's profile dlh Owned by: boonebgorges's profile boonebgorges
Milestone: 4.9.7 Priority: normal
Severity: normal Version: 4.7
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

Two identical calls to get_terms() with 'fields' => 'all_with_object_id' will return an array of WP_Term objects for the first call but an array of stdClass objects for the second call if the objects are retrieved from the cache.

It looks to me like this was caused by a missed case of updating

if ( 'all' === $_fields )

to

if ( 'all' === $_fields || 'all_with_object_id' === $_fields )

in [38667]. It seems unintentional, but I might be missing something.

The attached patch includes a test demonstrating the issue and a potential patch.

Attachments (1)

44221.diff (1.7 KB) - added by dlh 6 years ago.

Download all attachments as: .zip

Change History (4)

@dlh
6 years ago

#1 @boonebgorges
6 years ago

  • Milestone changed from Awaiting Review to 4.9.7

Good catch, @dlh. This does appear to be a mistake in [38667].

#2 @boonebgorges
6 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 43313:

Taxonomy: Improve cache handling when querying for terms using all_with_object_id.

When a term query using fields=all_with_object_id hits the cache, the
cached stdClass objects must be converted to WP_Term objects. This
was overlooked when WP_Term_Query was refactored to support object
queries in [38667].

Props dlh.
Fixes #44221.

#3 @boonebgorges
6 years ago

In 43314:

Taxonomy: Improve cache handling when querying for terms using all_with_object_id.

When a term query using fields=all_with_object_id hits the cache, the
cached stdClass objects must be converted to WP_Term objects. This
was overlooked when WP_Term_Query was refactored to support object
queries in [38667].

Merges [43313] to the 4.9 branch.

Props dlh.
Fixes #44221.

Note: See TracTickets for help on using tickets.