[wp-trac] [WordPress Trac] #31086: Uniform results for getting terms
WordPress Trac
noreply at wordpress.org
Wed Jan 21 13:21:43 UTC 2015
#31086: Uniform results for getting terms
--------------------------+-----------------------------
Reporter: joshlevinson | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Currently, `get_the_terms` gets data from two places: from
`get_object_term_cache`, or from `wp_get_object_terms`.
When it does not pull from the cache, the resulting array is numerically
zero-indexed.
However, when it '''does''' pull from cache (cases where
`update_post_caches` has been called before the call to `get_the_terms`
will make this occur), the resulting array uses term ID as the index for
each term object.
This makes it so that
[https://github.com/joshlevinson/CMB2/commit/fe06a7cd395d712403da5ef3eec926db91549f5a
workarounds] are necessary to reliably get the first term from the
resulting terms array.
I see two approaches:
1. Update `get_object_term_cache` so it always returns a zero-indexed
array
2. Update `wp_get_object_terms` so it always returns a term_id indexed
array
The logic that is present in `wp_get_object_terms` pretty much explicitly
makes it so that a zero-indexed array is always returned. Also, upon
altering it to return the term_id indexes, the following unit tests
failed:
{{{
Tests_Post_Objects::test_get_tags_input_property
}}}
{{{
Tests_Term_WpGetObjectTerms::test_should_not_filter_out_duplicate_terms_assoc
iated_with_different_objects
}}}
and sensibly so—they expected to get zero-indexed arrays and instead got
term_id indexed arrays.
This makes me believe that a much simpler change is in order—altering
`get_object_term_cache` so it always returns a zero-indexed array.
I've got a simple patch for this coming; I ran the
[http://develop.svn.wordpress.org/trunk/tests/phpunit/ unit tests that
ship with trunk] and they all passed.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31086>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list