Ticket #12891: relation-or.4.diff
File relation-or.4.diff, 1.8 KB (added by , 15 years ago) |
---|
-
wp-includes/taxonomy.php
524 524 global $wpdb; 525 525 526 526 $join = ''; 527 $where = '';527 $where = array(); 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)"; 581 582 $i++; 595 $where[] = "$alias.term_taxonomy_id $operator ($terms)"; 583 596 } 584 597 elseif ( 'NOT IN' == $operator ) { 598 585 599 if ( empty( $terms ) ) 586 600 continue; 587 601 588 602 $terms = implode( ',', $terms ); 589 603 590 $where .= " AND$primary_table.$primary_id_column NOT IN (591 SELECT object_id 592 FROM $wpdb->term_relationships 604 $where[] = "$primary_table.$primary_id_column NOT IN ( 605 SELECT object_id 606 FROM $wpdb->term_relationships 593 607 WHERE term_taxonomy_id IN ($terms) 594 608 )"; 595 609 } 610 611 $i++; 596 612 } 597 613 614 if ( !empty( $where ) ) 615 $where = ' AND ( ' . implode( " $relation ", $where ) . ' )'; 616 else 617 $where = ''; 618 598 619 return compact( 'join', 'where' ); 599 620 } 600 621