Fix logic for when excluding a non-existant term. See #12891
git-svn-id: http://svn.automattic.com/wordpress/trunk@16512 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
44733f9635
commit
36658f37ca
|
@ -1947,12 +1947,8 @@ class WP_Query {
|
||||||
if ( !empty( $this->tax_query ) ) {
|
if ( !empty( $this->tax_query ) ) {
|
||||||
$clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) );
|
$clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) );
|
||||||
|
|
||||||
if ( empty($clauses['join']) && empty($clauses['where']) ) {
|
$join .= $clauses['join'];
|
||||||
$where .= ' AND 0 = 1';
|
$where .= $clauses['where'];
|
||||||
} else {
|
|
||||||
$join .= $clauses['join'];
|
|
||||||
$where .= $clauses['where'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this->is_tax ) {
|
if ( $this->is_tax ) {
|
||||||
if ( empty($post_type) ) {
|
if ( empty($post_type) ) {
|
||||||
|
|
|
@ -552,9 +552,6 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
|
||||||
if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) {
|
if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) {
|
||||||
_transform_terms( $terms, $taxonomies, $field, 'term_id' );
|
_transform_terms( $terms, $taxonomies, $field, 'term_id' );
|
||||||
|
|
||||||
if ( empty( $terms ) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$children = array();
|
$children = array();
|
||||||
foreach ( $terms as $term ) {
|
foreach ( $terms as $term ) {
|
||||||
$children = array_merge( $children, get_term_children( $term, $taxonomy ) );
|
$children = array_merge( $children, get_term_children( $term, $taxonomy ) );
|
||||||
|
@ -568,12 +565,12 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
|
||||||
_transform_terms( $terms, $taxonomies, $field, 'term_taxonomy_id' );
|
_transform_terms( $terms, $taxonomies, $field, 'term_taxonomy_id' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty( $terms ) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$terms = implode( ',', $terms );
|
|
||||||
|
|
||||||
if ( 'IN' == $operator ) {
|
if ( 'IN' == $operator ) {
|
||||||
|
if ( empty( $terms ) )
|
||||||
|
return array( 'join' => '', 'where' => ' AND 0 = 1');
|
||||||
|
|
||||||
|
$terms = implode( ',', $terms );
|
||||||
|
|
||||||
$alias = $i ? 'tt' . $i : $wpdb->term_relationships;
|
$alias = $i ? 'tt' . $i : $wpdb->term_relationships;
|
||||||
|
|
||||||
$join .= " INNER JOIN $wpdb->term_relationships";
|
$join .= " INNER JOIN $wpdb->term_relationships";
|
||||||
|
@ -585,6 +582,11 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
elseif ( 'NOT IN' == $operator ) {
|
elseif ( 'NOT IN' == $operator ) {
|
||||||
|
if ( empty( $terms ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$terms = implode( ',', $terms );
|
||||||
|
|
||||||
$where .= " AND $primary_table.$primary_id_column NOT IN (
|
$where .= " AND $primary_table.$primary_id_column NOT IN (
|
||||||
SELECT object_id
|
SELECT object_id
|
||||||
FROM $wpdb->term_relationships
|
FROM $wpdb->term_relationships
|
||||||
|
@ -599,6 +601,9 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
|
||||||
function _transform_terms( &$terms, $taxonomies, $field, $resulting_field ) {
|
function _transform_terms( &$terms, $taxonomies, $field, $resulting_field ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
if ( empty( $terms ) )
|
||||||
|
return;
|
||||||
|
|
||||||
if ( $field == $resulting_field )
|
if ( $field == $resulting_field )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue