Repository navigation
Conversation
Fixes an issue where searching for terms containing ampersands (e.g. 'Tour & ' or 'Tour & Travel') failed to return matches because term names are stored with HTML entities in the database ('Tour & Travel') via _wp_specialchars().
WP_Term_Query::get_search_sql() now expands the search clauses to query both raw and HTML-entity-encoded forms when special characters are detected, ensuring consistent matches across partial and exact searches while preserving identical single-clause performance for standard terms.
Adds dedicated unit tests covering ampersands with trailing spaces, encoded entities, and standard term searches.
See #66279.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…ity in getSearchSql tests. In PHP 8.1+, reflection-accessed methods are accessible by default, and calling setAccessible() is deprecated in PHP 8.5. Guarding the call prevents deprecation errors when running tests on PHP 8.5+. See #66279.
Taxonomy: Allow searching terms containing ampersands and HTML entities
Trac ticket: https://core.trac.wordpress.org/ticket/66279
Description
When term names are saved in WordPress,
_wp_specialchars()encodes ampersands as&intowp_terms.name(priority 30 onpre_term_nameindefault-filters.php).Prior to this change,
WP_Term_Query::get_search_sql()created search clauses using only the raw$searchvalue:Because MySQL does not equate raw
'&'with'&', searching for terms containing ampersands (such as"Tour & ","Tour & Travel", or"& Travel") failed completely on bothwp-admin/edit-tags.phpand any queries powered byWP_Term_Query/get_terms( array( 'search' => ... ) ).Solution
In
WP_Term_Query::get_search_sql():_wp_specialchars( $search, ENT_COMPAT, 'UTF-8', true )).wp_specialchars_decode()) to support searches submitted with entities.ORcondition across both forms:Testing Instructions
Tour & Travel.Tour &(with a trailing space) on Posts -> Categories (wp-admin/edit-tags.php?taxonomy=category).Tour & Travelis found in the search results table.