Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#31118 closed defect (bug) (fixed)

get_terms() parameters do not respect multiple $taxonomies

Reported by: boonebgorges's profile boonebgorges Owned by: boonebgorges's profile boonebgorges
Milestone: 4.2 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

When passing an array of $taxonomies to get_terms(), a number of parameters only consider the first of these taxonomies: 'child_of', 'parent', 'pad_counts'. In addition, 'hierarchical' and 'pad_counts' will be forced to false if the first item in $taxonomies is non-hierarchical (eg, array( 'post_tag', 'category' )).

As far as I can tell, the pattern of looking only at the first of $taxonomies comes from the original porting of category functionality to the taxonomy component. My guess is that using $taxonomies[0] in place of $category was the quickest way to do a straight port. See [5525]. No one has ever come back to clean these bits up.

Change History (5)

#1 @theMikeD
9 years ago

I can't help but feel partially responsible for finding this! :) Good catch.

#2 @boonebgorges
9 years ago

In 31276:

In get_terms(), check hierarchy for all $taxonomies before bailing early from 'parent' or 'child_of'.

There is a pre-check in get_terms() that prevents an unnecessary database
query if the 'parent' or 'child_of' parameter is not found in the cached term
hierarchy (since a term without an index in the hierarchy cache has no
descendants). Previously, only the first item in the $taxonomies array was
being checked, with the result that an empty array was being erroneously
returned in cases where the 'parent' or 'child_of' term is in a subsequent
taxonomy.

See #31118.

#3 @boonebgorges
9 years ago

In 31284:

Ensure that 'pad_counts' is not discarded when the first of multiple taxonomies passed to get_terms() is non-hierarchical.

See #31118.

#4 @boonebgorges
9 years ago

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

In 31285:

Ensure that 'hierarchical' is respected in get_terms() when multiple taxonomies are passed.

Previously, attempts to descend the family tree of each term were done using
the first taxonomy in the $taxonomies array, with the result that terms not
belonging to that taxonomy were not found and their children not properly
parsed. We fix this bug by fetching each term's taxonomy with the SQL query,
and then using that taxonomy to get the correct children for each term.

Fixes #31118.

#5 @SergeyBiryukov
9 years ago

  • Milestone changed from Future Release to 4.2
Note: See TracTickets for help on using tickets.