[wp-trac] [WordPress Trac] #47314: Add "parent" parameter to get_term_by
WordPress Trac
noreply at wordpress.org
Thu Dec 5 17:27:55 UTC 2019
#47314: Add "parent" parameter to get_term_by
-----------------------------+------------------------------
Reporter: leogermani | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by leogermani):
Replying to [comment:1 SergeyBiryukov]:
> One option that comes to mind is to accept an array as the `$field`
parameter, something like this:
> {{{
> get_term_by( array( 'field' => 'name', 'parent' => $parent_term_id ),
'Child term', $taxonomy )
> }}}
> At that point, though, it seems like we're just reinventing
`get_terms()` with `'number' => 1`:
> {{{
> get_terms( array( 'name' => 'Child term', 'parent' => $parent_term_id,
'taxonomy' => $taxonomy, 'number' => 1 )
> }}}
Thanks for the reply!
`get_term_by` already uses `get_terms` internally... so it is basically a
shortcut to `get_terms` with some fixed parameters indeed. So you have a
point, if we add too many options to it, it misses the point of being a
shortcut.
I have been using `get_terms` as a replacement for `term_exists` and it
works well.
I think we have to ask:
* should we deprecate `term_exists()`? I understand it's not desirable to
change its behavior because it could break things
I think we should (if fixing it by adding a 'field' parameter isn't really
an option). We have a function that is not reliable.
If we deprecate it, we should recommend the new way of doing so, which
could be
* recommending `get_terms`,
* adding `parent` option to `get_term_by` or
* creating a new function.
I particularly think that this is something very useful and would be nice
to have something specific rather than having to use `get_terms`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47314#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list