[wp-trac] [WordPress Trac] #47314: Add "parent" parameter to get_term_by
WordPress Trac
noreply at wordpress.org
Thu Dec 5 16:21:36 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 SergeyBiryukov):
Replying to [ticket:47314 leogermani]:
> Looking at the function and all parameters it gets, we would have to
decide how to support this.
>
> This would be the first question to ask if one was to try an approach
for this. Adding as a new parameter does not look so good because there
already many and it would force the developer to use all of them if he/she
wanted to use `parent`. However adding support for a field like
`name_and_parent` or something like this, and having an array passed as
the `$value` doesn't look so pretty either.
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 )
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47314#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list