Ticket #12891: relation-or.3.diff
File relation-or.3.diff, 1.8 KB (added by , 15 years ago) |
---|
-
wp-includes/taxonomy.php
526 526 $join = ''; 527 527 $where = ''; 528 528 $i = 0; 529 530 if ( isset( $tax_query['relation'] ) && strtoupper( $tax_query['relation'] ) == 'OR' ) { 531 $relation = 'OR'; 532 } else { 533 $relation = 'AND'; 534 } 535 529 536 foreach ( $tax_query as $query ) { 537 if ( ! is_array( $query ) ) 538 continue; 539 530 540 extract( wp_parse_args( $query, array( 531 541 'taxonomy' => array(), 532 542 'terms' => array(), … … 566 576 } 567 577 568 578 if ( 'IN' == $operator ) { 569 if ( empty( $terms ) )570 return array( 'join' => '', 'where' => ' AND 0 = 1');571 579 580 if ( empty( $terms ) ) { 581 if ( 'OR' == $relation ) 582 continue; 583 else 584 return array( 'join' => '', 'where' => ' AND 0 = 1' ); 585 } 586 572 587 $terms = implode( ',', $terms ); 573 588 574 589 $alias = $i ? 'tt' . $i : $wpdb->term_relationships; … … 577 592 $join .= $i ? " AS $alias" : ''; 578 593 $join .= " ON ($primary_table.$primary_id_column = $alias.object_id)"; 579 594 580 $where .= " AND $alias.term_taxonomy_id $operator ($terms)"; 595 if ( $i ) 596 $where .= " $relation "; 581 597 582 $ i++;598 $where .= "$alias.term_taxonomy_id $operator ($terms)"; 583 599 } 584 600 elseif ( 'NOT IN' == $operator ) { 601 585 602 if ( empty( $terms ) ) 586 603 continue; 587 604 588 605 $terms = implode( ',', $terms ); 589 606 590 $where .= " AND $primary_table.$primary_id_column NOT IN ( 591 SELECT object_id 592 FROM $wpdb->term_relationships 607 if ( $i ) 608 $where .= " $relation "; 609 610 $where .= "$primary_table.$primary_id_column NOT IN ( 611 SELECT object_id 612 FROM $wpdb->term_relationships 593 613 WHERE term_taxonomy_id IN ($terms) 594 614 )"; 595 615 } 616 617 $i++; 596 618 } 597 619 620 $where = ' AND ( ' . $where . ' )'; 621 598 622 return compact( 'join', 'where' ); 599 623 } 600 624