[wp-trac] [WordPress Trac] #29839: Enhance get_terms to return only bottom child terms (terms without children) when taxonomy is heirarchical

WordPress Trac noreply at wordpress.org
Wed Nov 12 20:33:22 UTC 2014


#29839: Enhance get_terms to return only bottom child terms (terms without
children) when taxonomy is heirarchical
-------------------------------------------------+-------------------------
 Reporter:  theMikeD                             |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Taxonomy                             |  Review
 Severity:  normal                               |     Version:  4.0
 Keywords:  good-first-bug has-patch needs-      |  Resolution:
  unit-tests                                     |     Focuses:
-------------------------------------------------+-------------------------

Comment (by theMikeD):

 Here is what I have found.

 `_get_term_hierarchy` returns an array of arrays, and each of these sub-
 arrays is a termID-indexed list of that terms children; said another way,
 each sub-array contains the children of a given term. Crucially it does
 not list terms ''without'' children, so this can be used as the test for
 finding which terms are leaf terms: any term that does not have its own
 array has no children and is by definition a leaf term.

 So all we need to do is get a list of all terms, and any term that does
 not have an array in the results of `_get_term_hierarchy` is a leaf term.
 This is what I've done with the attached patch. Thoughts?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29839#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list