Opened 6 years ago
Closed 5 years ago
#45333 closed defect (bug) (wontfix)
term_exists might fail if slugs are changed
Reported by: | leogermani | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
The steps to reproduce this are:
- Create a term. For example: 'test 123'
- Change its slug to something completely different. For example, from 'test-123' to 'something-else'
- Now call the function
term_exists()
passing'test 123'
(with 2 empty spaces between test and 123) as the term name, along with the taxonomy.
You will notice that term_exists()
will not find it.
However, if you try to add this same term, with the two spaces, wp_insert_term()
won't allow it because it will detect it as a duplicate.
This issue I believe touches some bigger discussion around term_exists()
because this function handles the term name string in a different way that wp_insert_term()
does, which, in my opinion, creates an inconsistency.
I've seem some discussions around this on https://core.trac.wordpress.org/ticket/43345 and https://core.trac.wordpress.org/ticket/32248.
In this comment, @boonebgorges argues that "term_exists()
is a low-level function. Character encoding should be handled by the function that calls term_exists()
", but aknowledges the inconsistencies and says " In short: it's a mess, and I don't recommend using it - use get_term_by()
instead."
In fact get_term_by()
finds it.
So I guess the question is, shoud we touch term_exists() and make it find the same duplicates wp_insert_term() does?
Change History (3)
#3
@
5 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
See https://core.trac.wordpress.org/ticket/47099#comment:2. WP_Term_Query
is a workaround for this limitation in term_exists()
, and we should not touch term_exists()
for compatibility reasons.
Thanks for the ticket :)
Just realized that
get_term_by()
is not a good replacement forterm_exists()
because it does not expect term parent as a parameter...