Changeset 38275 for trunk/src/wp-includes/class-wp-meta-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-meta-query.php
r37860 r38275 107 107 108 108 /** 109 * @since 4.7.0 110 * @access protected 111 * @var wpdb 112 */ 113 protected $db; 114 115 /** 109 116 * Constructor. 110 117 * … … 138 145 */ 139 146 public function __construct( $meta_query = false ) { 140 if ( !$meta_query ) 147 $this->db = $GLOBALS['wpdb']; 148 149 if ( ! $meta_query ) { 141 150 return; 151 } 142 152 143 153 if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) { … … 485 495 * @access public 486 496 * 487 * @global wpdb $wpdb WordPress database abstraction object.488 *489 497 * @param array $clause Query clause, passed by reference. 490 498 * @param array $parent_query Parent query array. … … 499 507 */ 500 508 public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) { 501 global $wpdb;502 503 509 $sql_chunks = array( 504 510 'where' => array(), … … 538 544 $join .= " LEFT JOIN $this->meta_table"; 539 545 $join .= $i ? " AS $alias" : ''; 540 $join .= $ wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] );546 $join .= $this->db->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] ); 541 547 542 548 // All other JOIN clauses. … … 582 588 $sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL'; 583 589 } else { 584 $sql_chunks['where'][] = $ wpdb->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) );590 $sql_chunks['where'][] = $this->db->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) ); 585 591 } 586 592 } … … 602 608 case 'NOT IN' : 603 609 $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')'; 604 $where = $ wpdb->prepare( $meta_compare_string, $meta_value );610 $where = $this->db->prepare( $meta_compare_string, $meta_value ); 605 611 break; 606 612 … … 608 614 case 'NOT BETWEEN' : 609 615 $meta_value = array_slice( $meta_value, 0, 2 ); 610 $where = $ wpdb->prepare( '%s AND %s', $meta_value );616 $where = $this->db->prepare( '%s AND %s', $meta_value ); 611 617 break; 612 618 613 619 case 'LIKE' : 614 620 case 'NOT LIKE' : 615 $meta_value = '%' . $ wpdb->esc_like( $meta_value ) . '%';616 $where = $ wpdb->prepare( '%s', $meta_value );621 $meta_value = '%' . $this->db->esc_like( $meta_value ) . '%'; 622 $where = $this->db->prepare( '%s', $meta_value ); 617 623 break; 618 624 … … 620 626 case 'EXISTS' : 621 627 $meta_compare = '='; 622 $where = $ wpdb->prepare( '%s', $meta_value );628 $where = $this->db->prepare( '%s', $meta_value ); 623 629 break; 624 630 … … 629 635 630 636 default : 631 $where = $ wpdb->prepare( '%s', $meta_value );637 $where = $this->db->prepare( '%s', $meta_value ); 632 638 break; 633 639
Note: See TracChangeset
for help on using the changeset viewer.