WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 3 months ago

#26234 new defect (bug)

Passing array of taxonomies to the_terms() triggers "array to string" conversion warning

Reported by: johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.2
Component: Taxonomy Keywords: 2nd-opinion
Focuses: Cc:

Description

To duplicate in a loop, call:

the_terms( get_the_ID(), array( 'category', 'post_tag' ) );

I expected to output the terms for a post across multiple taxonomies. Instead, an array to string conversion warning is returned.

I've narrowed this down to an inconsistency in the way caching is handled between update_object_term_cache() and get_object_term_cache(), namely that update handles multiple taxonomies and relationships, and get assumes only one taxonomy is passed.

The call stack to the error looks something like:

  • the_terms()
  • get_the_term_list()
  • get_the_terms()
  • get_object_term_cache()

Each of the functions in the above stack safely handles multiple taxonomies, except for get_object_term_cache(). If get_object_term_cache() were fixed, wp_get_object_terms() would fire (which also safely handles multiple taxonomies) and the_terms() would work as I expected.

Attachments (2)

26234.patch (3.4 KB) - added by johnjamesjacoby 5 months ago.
I can get you a toe by 3 o'clock this afternoon, with nail polish
26234.2.patch (3.6 KB) - added by johnjamesjacoby 5 months ago.
Same as 26234.patch but also brings clean_object_term_cache() into the mix

Download all attachments as: .zip

Change History (4)

comment:1 johnjamesjacoby5 months ago

One possible, albeit hacky, solution, is to concatenate the taxonomies into a cache key, and pass that around instead.

Poking around in update_object_term_cache()will likely result in losing at least one finger (and probably a pinky toe) and although I'm justifiably afraid to go digging, my incoming patch does so with reckless abandon.

I'm also fully aware of the 5 year taxonomy plan, and prematurely agree that complicating things further for everyone is likely not worth the expense later. If nothing else, consider this a ticket for posterity until then.

(Edit: grammar all the words)

Last edited 5 months ago by johnjamesjacoby (previous) (diff)

johnjamesjacoby5 months ago

I can get you a toe by 3 o'clock this afternoon, with nail polish

johnjamesjacoby5 months ago

Same as 26234.patch but also brings clean_object_term_cache() into the mix

comment:2 stewarty3 months ago

Interestingly this affects me on PHP 5.4 but not on 5.3.x.

Something must've changed in the internals. I'm not sure what though, pretty much a noob with digging through PHP version changes

Would intentionally changing my array to a string before passing to this function help?

Stewart

Note: See TracTickets for help on using tickets.