[wp-trac] [WordPress Trac] #26234: Passing array of taxonomies to the_terms() triggers "array to string" conversion warning
WordPress Trac
noreply at wordpress.org
Sun Feb 1 03:13:53 UTC 2015
#26234: Passing array of taxonomies to the_terms() triggers "array to string"
conversion warning
------------------------------------------+-----------------------------
Reporter: johnjamesjacoby | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: Taxonomy | Version: 2.2
Severity: normal | Resolution:
Keywords: needs-unit-tests needs-patch | Focuses:
------------------------------------------+-----------------------------
Changes (by boonebgorges):
* keywords: has-patch needs-unit-tests => needs-unit-tests needs-patch
Comment:
The kind of cache concatenation suggested by [26234.2.patch] is not very
beautiful, and will result in significant cache pollution, since you might
end up with 'post_tag' relationships cached in many different places.
I suggest the following tack: Keep the `{$taxonomy}_relationships` caches
independent of one another. In `get_the_terms()`, do something like this:
{{{
$terms = array();
foreach ( (array) $taxonomy as $_taxonomy ) {
$_terms = get_object_term_cache( $post->ID, $_taxonomy );
if ( false === $_terms ) {
$_terms = wp_get_object_terms( $post->ID, $_taxonomy );
wp_cache_add( $post->ID, $terms, $_taxonomy . '_relationships' );
}
$terms = array_merge( $terms, $_terms );
}
}}}
Then do some logic to sort `$terms` by 'name' (since that's the only sort
order supported by `get_the_terms()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/26234#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list