[wp-trac] [WordPress Trac] #26903: get_terms returns no terms with 'parent' => 0 with non-empty child terms

WordPress Trac noreply at wordpress.org
Tue Jan 21 21:38:00 UTC 2014


#26903: get_terms returns no terms with 'parent' => 0 with non-empty child terms
--------------------------+-----------------------------
 Reporter:  mrwweb        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  3.8
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 I'm filing this to reopen #17365 which I think was closed incorrectly due
 to not understanding the OP.

 I don't want to repeat the entire ticket which has a lot of good details,
 so read it first.

 ------------------------

 I'll illustrate the bug with an example...

 Consider the following Food taxonomy term hierarchy and counts:

 * Cheese (0)
   * Cheddar (2)
   * Brie (7)
 * Crackers (0)
   * Butter (1)
   * Multigrain (3)
 * Fruit (0)
   * Cranberries (0)

 This structure implies 9 cheese posts, 4 cracker posts, and no fruit
 posts.

 According to the [http://codex.wordpress.org/Function_Reference/get_terms
 get_terms documentation], `get_terms( 'my_food_tax', array( 'parent' => 0
 ) )` should return Cheese and Crackers because `hierarchical` defaults to
 `true` and those terms (Cheese and Crackers) have non-empty children
 (Cheddar, Brie, Butter, and Multigrain). However, this currently returns
 NO terms.

 As the OP points out, this seems to be because setting `'parent' => 0`
 resets some of the stated defaults.

 However, this isn't just a problem with accurate documentation. As best I
 can tell, there is no way to override this behavior so the expected return
 value (Cheese and Crackers) is impossible to achieve without some kind of
 hack. I tried adding `'pad_counts' => true` and `'hierarchical' => true`
 in hopes that would help but it doesn't.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26903>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list