Changeset 38275 for trunk/src/wp-includes/class-wp-tax-query.php
- Timestamp:
- 08/18/2016 06:20:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-tax-query.php
r38079 r38275 93 93 94 94 /** 95 * @since 4.7.0 96 * @access protected 97 * @var wpdb 98 */ 99 protected $db; 100 101 /** 95 102 * Constructor. 96 103 * … … 120 127 */ 121 128 public function __construct( $tax_query ) { 129 $this->db = $GLOBALS['wpdb']; 130 122 131 if ( isset( $tax_query['relation'] ) ) { 123 132 $this->relation = $this->sanitize_relation( $tax_query['relation'] ); … … 388 397 * @access public 389 398 * 390 * @global wpdb $wpdb The WordPress database abstraction object.391 *392 399 * @param array $clause Query clause, passed by reference. 393 400 * @param array $parent_query Parent query array. … … 400 407 */ 401 408 public function get_sql_for_clause( &$clause, $parent_query ) { 402 global $wpdb;403 404 409 $sql = array( 405 410 'where' => array(), … … 433 438 if ( false === $alias ) { 434 439 $i = count( $this->table_aliases ); 435 $alias = $i ? 'tt' . $i : $ wpdb->term_relationships;440 $alias = $i ? 'tt' . $i : $this->db->term_relationships; 436 441 437 442 // Store the alias as part of a flat array to build future iterators. … … 441 446 $clause['alias'] = $alias; 442 447 443 $join .= " LEFT JOIN $wpdb->term_relationships";448 $join .= " LEFT JOIN {$this->db->term_relationships}"; 444 449 $join .= $i ? " AS $alias" : ''; 445 450 $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)"; … … 459 464 $where = "$this->primary_table.$this->primary_id_column NOT IN ( 460 465 SELECT object_id 461 FROM $wpdb->term_relationships466 FROM {$this->db->term_relationships} 462 467 WHERE term_taxonomy_id IN ($terms) 463 468 )"; … … 475 480 $where = "( 476 481 SELECT COUNT(1) 477 FROM $wpdb->term_relationships482 FROM {$this->db->term_relationships} 478 483 WHERE term_taxonomy_id IN ($terms) 479 484 AND object_id = $this->primary_table.$this->primary_id_column … … 482 487 } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) { 483 488 484 $where = $ wpdb->prepare( "$operator (489 $where = $this->db->prepare( "$operator ( 485 490 SELECT 1 486 FROM $wpdb->term_relationships487 INNER JOIN $wpdb->term_taxonomy488 ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id489 WHERE $wpdb->term_taxonomy.taxonomy = %s490 AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column491 FROM {$this->db->term_relationships} 492 INNER JOIN {$this->db->term_taxonomy} 493 ON {$this->db->term_taxonomy}.term_taxonomy_id = {$this->db->term_relationships}.term_taxonomy_id 494 WHERE {$this->db->term_taxonomy}.taxonomy = %s 495 AND {$this->db->term_relationships}.object_id = $this->primary_table.$this->primary_id_column 491 496 )", $clause['taxonomy'] ); 492 497 … … 598 603 * @since 3.2.0 599 604 * 600 * @global wpdb $wpdb The WordPress database abstraction object.601 *602 605 * @param array $query The single query. Passed by reference. 603 606 * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id', … … 605 608 */ 606 609 public function transform_query( &$query, $resulting_field ) { 607 global $wpdb;608 609 610 if ( empty( $query['terms'] ) ) 610 611 return; … … 629 630 $terms = implode( ",", $query['terms'] ); 630 631 631 $terms = $ wpdb->get_col( "632 SELECT $wpdb->term_taxonomy.$resulting_field633 FROM $wpdb->term_taxonomy634 INNER JOIN $wpdb->termsUSING (term_id)632 $terms = $this->db->get_col( " 633 SELECT {$this->db->term_taxonomy}.$resulting_field 634 FROM {$this->db->term_taxonomy} 635 INNER JOIN {$this->db->terms} USING (term_id) 635 636 WHERE taxonomy = '{$query['taxonomy']}' 636 AND $wpdb->terms.{$query['field']} IN ($terms)637 AND {$this->db->terms}.{$query['field']} IN ($terms) 637 638 " ); 638 639 break; 639 640 case 'term_taxonomy_id': 640 641 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 641 $terms = $ wpdb->get_col( "642 $terms = $this->db->get_col( " 642 643 SELECT $resulting_field 643 FROM $wpdb->term_taxonomy644 FROM {$this->db->term_taxonomy} 644 645 WHERE term_taxonomy_id IN ($terms) 645 646 " ); … … 647 648 default: 648 649 $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); 649 $terms = $ wpdb->get_col( "650 $terms = $this->db->get_col( " 650 651 SELECT $resulting_field 651 FROM $wpdb->term_taxonomy652 FROM {$this->db->term_taxonomy} 652 653 WHERE taxonomy = '{$query['taxonomy']}' 653 654 AND term_id IN ($terms)
Note: See TracChangeset
for help on using the changeset viewer.