diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 27fb326204..1566fbb32b 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -696,8 +696,15 @@ class WP_Object_Query { foreach ( $this->tax_query as $query ) { if ( !isset( $query['include_children'] ) ) $query['include_children'] = true; + $query['do_query'] = false; - $sql[] = get_objects_in_term( $query['terms'], $query['taxonomy'], $query ); + + $sql_single = get_objects_in_term( $query['terms'], $query['taxonomy'], $query ); + + if ( empty( $sql_single ) ) + return ' AND 0 = 1'; + + $sql[] = $sql_single; } if ( 1 == count( $sql ) ) { diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 1b715a092e..3b50a2d732 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -466,16 +466,14 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) { return new WP_Error( 'invalid_taxonomy', sprintf( __( 'Invalid Taxonomy: %s' ), $taxonomy ) ); } - $terms = array_unique( (array) $terms ); - if ( empty($terms) ) - continue; - if ( !in_array( $field, array( 'term_id', 'slug', 'name' ) ) ) $field = 'term_id'; if ( !in_array( $operator, array( 'IN', 'NOT IN' ) ) ) $operator = 'IN'; + $terms = array_unique( (array) $terms ); + if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) { $children = array(); foreach ( $terms as $term ) { @@ -492,6 +490,9 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) { $field = 'term_id'; } + if ( empty( $terms ) ) + return $do_query ? array() : ''; + $taxonomies = "'" . implode( "', '", $taxonomies ) . "'"; switch ( $field ) { @@ -527,10 +528,7 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) { break; } - if ( !$do_query ) - return $sql; - - return $wpdb->get_col( $sql ); + return $do_query ? $wpdb->get_col( $sql ) : $sql; } /**