[wp-trac] [WordPress Trac] #50294: Ampersand and other symbols in term_exists do not get encoded properly
WordPress Trac
noreply at wordpress.org
Mon Jun 1 14:59:23 UTC 2020
#50294: Ampersand and other symbols in term_exists do not get encoded properly
--------------------------+-----------------------------
Reporter: SeBsZ | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.4.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When calling term_exists as follows:
{{{
$matchingterms = term_exists('Nice Hotels & Apartments, 'customtaxonomy',
0);
}}}
I noticed the resulting term name query looks like this:
{{{
SELECT
tt.term_id,
tt.term_taxonomy_id
FROM
wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
WHERE
t.NAME = 'Nice Hotels & Apartments'
AND tt.parent = 0
AND tt.taxonomy = 'customtaxonomy'
ORDER BY
t.term_id ASC
LIMIT 1
}}}
This then fails to return any results even though it is in the database.
But in the database the ampersand is encoded &:
wp_terms:
term_id | name | slug
11851 | Nice Hotels & Apartments | nice-hotels-apartments-different-
slug
My code then decides the term does not exist yet, but creation of a new
term using wp_insert_term with the same term name "Nice Hotels &
Apartments" then fails (correctly) with the message "A term with the name
provided already exists in this taxonomy."
I believe the behavior between the two functions term_exists and
wp_insert_term is not consistent. Can someone take a look at this?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50294>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list