diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 043454c9d9..5254eef426 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1857,13 +1857,12 @@ function get_terms( $taxonomies, $args = '' ) { } if ( ! empty( $args['name'] ) ) { - if ( is_array( $args['name'] ) ) { - $name = array_map( 'sanitize_text_field', $args['name'] ); - $where .= " AND t.name IN ('" . implode( "', '", array_map( 'esc_sql', $name ) ) . "')"; - } else { - $name = sanitize_text_field( $args['name'] ); - $where .= $wpdb->prepare( " AND t.name = %s", $name ); + $names = (array) $args['name']; + foreach ( $names as &$_name ) { + $_name = sanitize_term_field( 'name', $_name, 0, reset( $taxonomies ), 'db' ); } + + $where .= " AND t.name IN ('" . implode( "', '", array_map( 'esc_sql', $names ) ) . "')"; } if ( ! empty( $args['slug'] ) ) { diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index 2dbbaffa5d..333e87ec6a 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -540,6 +540,34 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $this->assertEqualSets( array( $t3, $t1 ), $found ); } + /** + * @ticket 32248 + */ + public function test_name_should_match_encoded_html_entities() { + register_taxonomy( 'wptests_tax', 'post' ); + + $t = $this->factory->term->create( array( + 'taxonomy' => 'wptests_tax', + 'name' => 'Foo & Bar', + 'slug' => 'foo-and-bar', + ) ); + + $found = get_terms( 'wptests_tax', array( + 'hide_empty' => false, + 'fields' => 'ids', + 'name' => 'Foo & Bar', + ) ); + $this->assertEqualSets( array( $t ), $found ); + + // array format. + $found = get_terms( 'wptests_tax', array( + 'hide_empty' => false, + 'fields' => 'ids', + 'name' => array( 'Foo & Bar' ), + ) ); + $this->assertEqualSets( array( $t ), $found ); + } + /** * @ticket 29839 */