diff --git a/wp-includes/class-wp-term-query.php b/wp-includes/class-wp-term-query.php index 79ec315c4f..74386bc9ab 100644 --- a/wp-includes/class-wp-term-query.php +++ b/wp-includes/class-wp-term-query.php @@ -474,7 +474,10 @@ class WP_Term_Query { $this->sql_clauses['where']['exclusions'] = preg_replace( '/^\s*AND\s*/', '', $exclusions ); } - if ( ! empty( $args['name'] ) ) { + if ( + ( ! empty( $args['name'] ) ) || + ( is_string( $args['name'] ) && 0 !== strlen( $args['name'] ) ) + ) { $names = (array) $args['name']; foreach ( $names as &$_name ) { // `sanitize_term_field()` returns slashed data. @@ -484,7 +487,10 @@ class WP_Term_Query { $this->sql_clauses['where']['name'] = "t.name IN ('" . implode( "', '", array_map( 'esc_sql', $names ) ) . "')"; } - if ( ! empty( $args['slug'] ) ) { + if ( + ( ! empty( $args['slug'] ) ) || + ( is_string( $args['slug'] ) && 0 !== strlen( $args['slug'] ) ) + ) { if ( is_array( $args['slug'] ) ) { $slug = array_map( 'sanitize_title', $args['slug'] ); $this->sql_clauses['where']['slug'] = "t.slug IN ('" . implode( "', '", $slug ) . "')"; diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index a7c6a4d267..f8bc57d039 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -835,6 +835,15 @@ function get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter return false; } + // No need to perform a query for empty 'slug' or 'name'. + if ( 'slug' === $field || 'name' === $field ) { + $value = (string) $value; + + if ( 0 === strlen( $value ) ) { + return false; + } + } + if ( 'id' === $field || 'term_id' === $field ) { $term = get_term( (int) $value, $taxonomy, $output, $filter ); if ( is_wp_error( $term ) || null === $term ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 544d915035..b87ebec072 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-40292'; +$wp_version = '4.8-alpha-40293'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.