Opened 14 hours ago
Last modified 14 hours ago
#66281 new enhancement
Taxonomy: Add description to the fields searched by WP_Term_Query / admin term search
| Reported by: | abditsori | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Taxonomy | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
WP_Term_Query::get_search_sql() hardcodes its search matching to
just two columns:
return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like );
A term's description (stored on wp_term_taxonomy) is never
considered, even though:
wp_term_taxonomyis already unconditionallyINNER JOINed into every term query (it's wheretaxonomy,parent, andcountcome from too), so no new join is required to reachdescription.- A
description__likearg already exists for exact-field LIKE matching — it's just never combined withsearch.
Because edit-tags.php?taxonomy=X is the single shared admin screen
for every taxonomy (Categories, Tags, Link Categories, and any custom
taxonomy with an admin UI all use the same WP_Terms_List_Table
class), this affects all of them identically: searching the admin
term list only matches name/slug, never description, with no way to
opt in short of hooking terms_clauses and hand-building a `tt.description
LIKE` clause in a plugin.
Steps to reproduce:
- Create a category (or tag) with a short, generic name but a distinctive description, e.g. name "Misc", description containing the word "pineapple".
- Go to Posts > Categories (or Posts > Tags) in wp-admin.
- Search for "pineapple".
Expected: the term is found, since "pineapple" appears in its
description.
Actual: no results — only name/slug are searched.
Suggested fix: add an opt-in search_columns query var to
WP_Term_Query (accepting 'name', 'slug', 'description';
default empty array, preserving today's name+slug-only behavior for
every existing caller), and have get_search_sql() build its OR'd
LIKE clause from the configured columns instead of the hardcoded
pair — mirroring the existing user_search_columns pattern already
used by WP_User_Query. WP_Terms_List_Table::prepare_items() then
opts in to all three columns for the admin search box (both the
get_terms() call and the wp_count_terms() pagination count, so the
displayed total stays consistent with the actual results).
Change History (1)
This ticket was mentioned in PR #14138 on WordPress/wordpress-develop by @abditsori.
14 hours ago
#1
- Keywords has-patch has-unit-tests added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/66281
Summary
The admin Categories/Tags search box (
edit-tags.php?taxonomy=X) only ever matched a term's name or slug.WP_Term_Query::get_search_sql()hardcodes((t.name LIKE %s) OR (t.slug LIKE %s))— it never considerstt.description, even thoughwp_term_taxonomy(wheredescriptionlives) is already unconditionallyINNER JOINed for every term query, and adescription__likearg already exists for exact-field matching (just not combined withsearch).Since
edit-tags.phpis a single shared admin screen for every taxonomy (parameterized by?taxonomy=, always using the sameWP_Terms_List_Tableclass), this isn't Categories-specific — it fixes Tags, Categories, and any custom taxonomy with an admin UI at once.Changes
search_columnsquery var toWP_Term_Query(defaultarray(), preserving today's name+slug-only behavior for every existing caller ofget_terms()/WP_Term_Query). Accepts'name','slug','description'.get_search_sql()now builds itsOR'dLIKEclause from the configured columns instead of being hardcoded to two columns. MirrorsWP_User_Query'suser_search_columnspattern, including an equivalentterm_search_columnsfilter for parity.WP_Terms_List_Table::prepare_items()opts in toarray( 'name', 'slug', 'description' )for both theget_terms()call and thewp_count_terms()pagination count (so the "X items" total stays consistent with what's actually returned).((t.name LIKE %s) OR (t.slug LIKE %s))SQL string is byte-identical to before whensearch_columnsisn't passed, so zero behavior change for any existing caller.Test plan
php -lon all three changed files.test_get_terms_search_does_not_match_description_by_defaultandtest_get_terms_search_columns_can_include_descriptiontogetTerms.php.tests/phpunit/tests/term/getTerms.php(116 tests) andtests/phpunit/tests/term/query.php(43 tests) — all passing.--group taxonomysuite (911 tests) — all passing, one pre-existing unrelated PHPUnit-version warning.WP_Terms_List_Table::prepare_items()path for bothcategoryandpost_tagtaxonomies: a term matched only by description is found, a non-matching term is excluded, for both.