[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
Sat Nov 15 20:53:25 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:  Future
Component:  Taxonomy                            |  Release
 Severity:  normal                              |     Version:  4.0
 Keywords:  4.2-early good-first-bug has-patch  |  Resolution:
                                                |     Focuses:
------------------------------------------------+--------------------------

Comment (by theMikeD):

 Replying to [comment:30 boonebgorges]:
 > * I think the '_terms' part of 'childless_terms' is redundant. (We don't
 say 'parent_term' or 'term_is_child_of', etc.)

 True. How about just `childless` then?

 > * You got the right place for the docblock :) I don't think it's correct
 to say that 'childless' is the opposite of 'parent', because 'parent'
 takes a term ID and returns only children of the parent, while 'childless'
 doesn't care what part of the taxonomy tree you're in and takes a boolean
 argument.

 The results are opposite though, which is what I was referring to. I'll
 remove the assertion though just for clarity's sake.

 > * You bail out of the function with an empty array if the taxonomy
 hierarchy is empty. Why? (This is kind of a trick question: a couple other
 parameters do this, and it's not totally obvious why they do it either.)
 If it's intended to save database queries, or prevent false positives, or
 whatever, it would be nice to see a unit test that demonstrates it.
 Alternatively, if that block doesn't affect anything, we should tear it
 out.

 I bomb out for the same reason that `parent` does: there is no such thing
 as a child term if there is no hierarchy. If I didn't then this option
 would be the same as `all` which doesn't sit with me.

 > * When you are building the `$exclusions` string, make sure you run each
 item through `intval()` - better safe than sorry when building SQL
 queries.

 This would only be the case if `_get_term_hierarchy()` somehow returned
 non-IDs, right? I don't find that likely, but I'll add the `intval()`
 wrapper to be safe.

 > * It's spelled "hierarchical" and "hierarchy" :)

 And one day, I'm certain I'll spell it that way too!

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


More information about the wp-trac mailing list