[wp-trac] [WordPress Trac] #17365: get_terms doesn't return terms with no posts if you specify a parent

WordPress Trac wp-trac at lists.automattic.com
Tue May 10 11:52:19 UTC 2011


#17365: get_terms doesn't return terms with no posts if you specify a parent
--------------------------+-----------------------------
 Reporter:  mark8barnes   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  3.1.2
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 get_terms doesn't return terms with no posts if you specify a parent (see
 also #15626 for a related bug). Let's imagine the following term
 structure:

 {{{
 ---parent_term (0 count)
     |---child_term (10 count)
 }}}

 Calling `get_terms('category', array('parent' => 0))` should return both
 terms according to the documentation, but it doesn't. The documentation
 says that `hierarchical` defaults to true, which should '''"include terms
 that have non-empty descendants"'''. It's broken because the following
 code runs if a parent argument is present (lines 1139-3 of
 taxonomies.php).

 {{{
 if ( !$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) ||
         '' !== $args['parent'] ) {
 $args['child_of'] = 0;
 $args['hierarchical'] = false;
 $args['pad_counts'] = false;
 }}}

 But nothing in the parent section of the documentation suggests that
 adding a parent will change the other defaults. The consequence of the
 above code comes in lines 1266-7:

 {{{
 if ( $hide_empty && !$hierarchical )
         $where .= ' AND tt.count > 0';
 }}}

 which means the parent_term is not being returned because it has a count
 of zero, and I can't walk down the tree to get the other terms.

 At the very least, set this paramenter as default in $defaults, before
 `$args = wp_parse_args( $args, $defaults )` (rather than in `$args`
 afterwards) which would at least allow us to override this behaviour
 through explicit `$atts`. But it would be more logical simply to remove
 the test for `'' !== args['parent']` altogther, inline with the existing
 documentation.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17365>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list