Ticket #12891: get-tax-sql-or.diff
File get-tax-sql-or.diff, 2.2 KB (added by , 15 years ago) |
---|
-
query.php
1948 1948 $clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) ); 1949 1949 1950 1950 $join .= $clauses['join']; 1951 $where .= $clauses['where'];1951 $where .= ' AND ' . $clauses['where']; 1952 1952 1953 1953 if ( empty($post_type) ) { 1954 1954 $post_type = 'any'; -
taxonomy.php
520 520 * @param string $primary_id_column 521 521 * @return string 522 522 */ 523 function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {523 function get_tax_sql( $tax_query, $primary_table, $primary_id_column, $ignore='', $relationship = 'AND', $i = 0 ) { 524 524 global $wpdb; 525 525 526 526 $join = ''; 527 527 $where = ''; 528 $i = 0;529 528 foreach ( $tax_query as $query ) { 529 530 if ( is_array( $query ) && array_key_exists ( 'relationship', $query ) ) { 531 $rel = $query['relationship']; 532 unset($query['relationship']); 533 $ret = get_tax_sql($query, $primary_table, $primary_id_column, $ignore, $rel, $i); 534 535 $join .= $ret['join']; 536 $where .= '( ' . $ret['where'] . ' )'; 537 $i = $ret['i']; 538 continue; 539 } 540 530 541 extract( wp_parse_args( $query, array( 531 542 'taxonomy' => array(), 532 543 'terms' => array(), … … 539 550 540 551 foreach ( $taxonomies as $taxonomy ) { 541 552 if ( ! taxonomy_exists( $taxonomy ) ) 542 return ' AND0 = 1';553 return '0 = 1'; 543 554 } 544 555 545 556 $taxonomies = "'" . implode( "', '", $taxonomies ) . "'"; … … 579 590 $join .= " INNER JOIN $wpdb->term_relationships"; 580 591 $join .= $i ? " AS $alias" : ''; 581 592 $join .= " ON ($primary_table.$primary_id_column = $alias.object_id)"; 593 594 if ($i) $where .= " $relationship"; 595 $where .= " $alias.term_taxonomy_id $operator ($terms)"; 582 596 583 $where .= " AND $alias.term_taxonomy_id $operator ($terms)";584 585 597 $i++; 586 598 } 587 599 elseif ( 'NOT IN' == $operator ) { … … 592 604 )"; 593 605 } 594 606 } 595 return compact( 'join', 'where' );607 return compact( 'join', 'where', 'i' ); 596 608 } 597 609 598 610 function _transform_terms( &$terms, $taxonomies, $field, $resulting_field ) {