WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 2 months ago

#50294 new defect (bug)

Ampersand and other symbols in term_exists do not get encoded properly

Reported by: SeBsZ Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.4.1
Component: Taxonomy Keywords:
Focuses: Cc:

Description

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?

Change History (1)

#1 @markparnell
2 months ago

  • Component changed from General to Taxonomy
Note: See TracTickets for help on using tickets.