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:
scribu 2010-11-20 21:28:50 +00:00
parent 44733f9635
commit 36658f37ca
2 changed files with 15 additions and 14 deletions

View File

@ -1947,12 +1947,8 @@ class WP_Query {
if ( !empty( $this->tax_query ) ) {
$clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) );
if ( empty($clauses['join']) && empty($clauses['where']) ) {
$where .= ' AND 0 = 1';
} else {
$join .= $clauses['join'];
$where .= $clauses['where'];
}
$join .= $clauses['join'];
$where .= $clauses['where'];
if ( $this->is_tax ) {
if ( empty($post_type) ) {

View File

@ -552,9 +552,6 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) {
_transform_terms( $terms, $taxonomies, $field, 'term_id' );
if ( empty( $terms ) )
continue;
$children = array();
foreach ( $terms as $term ) {
$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' );
}
if ( empty( $terms ) )
continue;
$terms = implode( ',', $terms );
if ( 'IN' == $operator ) {
if ( empty( $terms ) )
return array( 'join' => '', 'where' => ' AND 0 = 1');
$terms = implode( ',', $terms );
$alias = $i ? 'tt' . $i : $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++;
}
elseif ( 'NOT IN' == $operator ) {
if ( empty( $terms ) )
continue;
$terms = implode( ',', $terms );
$where .= " AND $primary_table.$primary_id_column NOT IN (
SELECT object_id
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 ) {
global $wpdb;
if ( empty( $terms ) )
return;
if ( $field == $resulting_field )
return;