From 1ffc11d6a19265ce9ee81570cc5e9323ed470db6 Mon Sep 17 00:00:00 2001 From: Mohamed Samir <167022012+MoS2mir@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:26:56 +0200 Subject: [PATCH 1/2] Term query: match non-ASCII slugs in search. Non-ASCII slugs are stored percent-encoded, so also match the encoded form of the search string against the term slug. See #43626. --- src/wp-includes/class-wp-term-query.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 13e768c52de87..c2ab012b44414 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -1128,6 +1128,17 @@ protected function get_search_sql( $search ) { $like = '%' . $wpdb->esc_like( $search ) . '%'; + /* + * Slugs containing non-ASCII characters are stored percent-encoded, so also + * match the encoded form of the search string against the slug. + */ + $slug_search = strtolower( utf8_uri_encode( $search ) ); + if ( $slug_search !== $search ) { + $slug_like = '%' . $wpdb->esc_like( $slug_search ) . '%'; + + return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s) OR (t.slug LIKE %s))', $like, $like, $slug_like ); + } + return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); } From 4cd08c8c867fd213e5abae83677d5ccaebb766aa Mon Sep 17 00:00:00 2001 From: Mohamed Samir <167022012+MoS2mir@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:27:21 +0200 Subject: [PATCH 2/2] Tests: Add a test for searching terms by non-ASCII slug. See #43626. --- tests/phpunit/tests/term/getTerms.php | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index 066e127867b5c..aedd402ff8af4 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -446,6 +446,41 @@ public function test_get_terms_search() { $this->assertSameSets( array( $term_id1, $term_id2 ), $terms ); } + /** + * @ticket 43626 + */ + public function test_get_terms_search_matches_non_ascii_slug() { + $term_id1 = self::factory()->tag->create( + array( + 'name' => 'tag1', + 'slug' => 'slug1', + ) + ); + $term_id2 = self::factory()->tag->create( + array( + 'name' => 'تاج1', + 'slug' => 'سلج1', + ) + ); + $term_id3 = self::factory()->tag->create( + array( + 'name' => 'Foo', + 'slug' => 'foo', + ) + ); + + $args = array( + 'hide_empty' => false, + 'fields' => 'ids', + ); + + $this->assertSame( array( $term_id1 ), get_terms( 'post_tag', $args + array( 'search' => 'slug1' ) ), 'An ASCII slug should still match.' ); + $this->assertSame( array( $term_id2 ), get_terms( 'post_tag', $args + array( 'search' => 'سلج1' ) ), 'A non-ASCII slug should match.' ); + $this->assertSame( array( $term_id2 ), get_terms( 'post_tag', $args + array( 'search' => 'تاج1' ) ), 'A non-ASCII name should still match.' ); + $this->assertSame( array(), get_terms( 'post_tag', $args + array( 'search' => 'سلج2' ) ), 'A non-matching non-ASCII search should not match.' ); + $this->assertNotContains( $term_id3, get_terms( 'post_tag', $args + array( 'search' => 'سلج1' ) ) ); + } + /** * @ticket 8214 */