Ticket #37038: 37038.patch
File 37038.patch, 2.9 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-tax-query.php
614 614 615 615 $resulting_field = sanitize_key( $resulting_field ); 616 616 617 switch ( $query['field'] ) { 618 case 'slug': 619 case 'name': 620 foreach ( $query['terms'] as &$term ) { 621 /* 622 * 0 is the $term_id parameter. We don't have a term ID yet, but it doesn't 623 * matter because `sanitize_term_field()` ignores the $term_id param when the 624 * context is 'db'. 625 */ 626 $term = "'" . esc_sql( sanitize_term_field( $query['field'], $term, 0, $query['taxonomy'], 'db' ) ) . "'"; 627 } 617 $key = md5( serialize( $query ) . $resulting_field ); 618 $last_changed = wp_cache_get( 'last_changed', 'terms' ); 619 if ( ! $last_changed ) { 620 $last_changed = microtime(); 621 wp_cache_set( 'last_changed', $last_changed, 'terms' ); 622 } 623 $cache_key = "transform_query:$key:$last_changed"; 624 $terms = wp_cache_get( $cache_key, 'terms' ); 625 if ( false === $terms ) { 626 switch ( $query['field'] ) { 627 case 'slug': 628 case 'name': 629 foreach ( $query['terms'] as &$term ) { 630 /* 631 * 0 is the $term_id parameter. We don't have a term ID yet, but it doesn't 632 * matter because `sanitize_term_field()` ignores the $term_id param when the 633 * context is 'db'. 634 */ 635 $term = "'" . esc_sql( sanitize_term_field( $query['field'], $term, 0, $query['taxonomy'], 'db' ) ) . "'"; 636 } 628 637 629 $terms = implode( ",", $query['terms'] );638 $terms = implode( ",", $query['terms'] ); 630 639 631 $terms = $wpdb->get_col( "640 $terms = $wpdb->get_col( " 632 641 SELECT $wpdb->term_taxonomy.$resulting_field 633 642 FROM $wpdb->term_taxonomy 634 643 INNER JOIN $wpdb->terms USING (term_id) … … 635 644 WHERE taxonomy = '{$query['taxonomy']}' 636 645 AND $wpdb->terms.{$query['field']} IN ($terms) 637 646 " ); 638 break;639 case 'term_taxonomy_id':640 $terms = implode( ',', array_map( 'intval', $query['terms'] ) );641 $terms = $wpdb->get_col( "647 break; 648 case 'term_taxonomy_id': 649 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 650 $terms = $wpdb->get_col( " 642 651 SELECT $resulting_field 643 652 FROM $wpdb->term_taxonomy 644 653 WHERE term_taxonomy_id IN ($terms) 645 654 " ); 646 break;647 default:648 $terms = implode( ',', array_map( 'intval', $query['terms'] ) );649 $terms = $wpdb->get_col( "655 break; 656 default: 657 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 658 $terms = $wpdb->get_col( " 650 659 SELECT $resulting_field 651 660 FROM $wpdb->term_taxonomy 652 661 WHERE taxonomy = '{$query['taxonomy']}' 653 662 AND term_id IN ($terms) 654 663 " ); 664 } 665 wp_cache_add( $cache_key, $terms, 'terms' ); 655 666 } 656 667 657 668 if ( 'AND' == $query['operator'] && count( $terms ) < count( $query['terms'] ) ) {