[wp-trac] [WordPress Trac] #47099: term_exists fail when term is surrounded with brackets
WordPress Trac
noreply at wordpress.org
Fri May 10 16:00:44 UTC 2019
#47099: term_exists fail when term is surrounded with brackets
-------------------------------------+----------------------
Reporter: leogermani | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Taxonomy | Version:
Severity: normal | Resolution: wontfix
Keywords: close reporter-feedback | Focuses:
-------------------------------------+----------------------
Changes (by boonebgorges):
* status: new => closed
* resolution: => wontfix
* milestone: Awaiting Review =>
Comment:
`term_exists()` was built to be a "magic" function: you can pass it
different kinds of input (`name` or `slug`) and it'll magically try to
figure out which one you mean. This kind of "magic" is the root of the
issue described in this ticket, as well as many other current and past
`term_exists()` tickets. This indicates that we should not be creating
more magic :)
You're right that `get_term_by()` doesn't support 'parent'. Perhaps it
should - I can see an argument for doing so. Maybe you could open a
separate enhancement ticket with this idea?
Alternatively, you can always use `get_terms()` or `WP_Term_Query`, which
is what `get_term_by()` uses internally anyway:
{{{
$found = get_terms( [
'taxonomy' => $taxonomy,
'parent' => $parent_id,
'name' => $name,
] );
if ( $found ) {
$term = array_shift( $terms );
} else {
$term = null;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47099#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list