[wp-trac] [WordPress Trac] #37728: hide_empty doesn't work correctly in get_terms when no taxonomy specified
WordPress Trac
noreply at wordpress.org
Fri Aug 19 00:42:04 UTC 2016
#37728: hide_empty doesn't work correctly in get_terms when no taxonomy specified
--------------------------+-----------------------------
Reporter: smerriman | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.5
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
In #35495, the taxonomy argument to `get_terms` was made optional. Calling
get_terms without specifying a taxonomy will return terms from all
taxonomies.
However, if taxonomy isn't provided, hide_empty (when true, as per
default) does not work correctly. Parent terms which are empty themselves
but have nonempty child terms are not returned.
You can replicate this by creating an empty category with non-empty child
categories. Using:
`get_terms()` - won't include the category
`get_terms(array('taxonomy'=>'category'))` - will include the category
`get_terms(array('taxonomy'=>array('category','post_tag')))` - will
include the category
This is caused by the `get_terms` function in `WP_Term_Query`.
`$has_hierarchical_tax` gets set to true if a single hierarchical taxonomy
is passed, or multiple taxonomies with at least one hierarchical. However,
if no taxonomies are passed, this never gets set to true.
In this case it should be set to true, since it will at minimum include
the in-built `category` taxonomy.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37728>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list