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