[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
Tue Dec 30 21:55:08 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: 4.2
Component: Taxonomy | Version: 4.0
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------+------------------
Changes (by boonebgorges):
* keywords: 4.2-early has-patch needs-unit-tests 2nd-opinion => has-patch
* milestone: Future Release => 4.2
Comment:
Replying to [comment:58 johnbillion]:
> Finally, I'm not entirely convinced this argument is very useful. It can
be manually implemented with minimal code:
>
> {{{
> $terms = get_terms( $taxonomy, array(
> 'exclude' => array_keys( _get_term_hierarchy( $taxonomy ) )
> ) );
> }}}
The same argument could be made for all parameters related to term
hierarchy - child_of, parent, exclude_tree, etc could all be implemented
using include/exclude, by making reference to `_get_term_hierarchy()`. We
provide these params as a convenience for two reasons. (1) Doing
everything with 'include' and 'exclude' means that you need to do various
`array_intersect()` tricks if you want to do anything of moderate
complexity (which would otherwise be accomplished by using standalone
arguments together). (2) As theMikeD notes, `_get_term_hierarchy()` is
part of our internal cache implementation, which plugin devs should be
free (encouraged!) to ignore.
Your `foreach` suggestion seems fine to me.
I can think of a number of legit use cases for wanting to pull up terminal
nodes in a taxonomy hierarchy. So unless there's a pressing argument
against it, let's go with this param for 4.2. Leaving open for the time
being because I'm still not bonkers about the 'childless' naming
convention.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29839#comment:61>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list