Changeset 42343 for trunk/src/wp-includes/class-wp-tax-query.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-tax-query.php
r41688 r42343 48 48 * @var string 49 49 */ 50 private static $no_results = array( 'join' => array( '' ), 'where' => array( '0 = 1' ) ); 50 private static $no_results = array( 51 'join' => array( '' ), 52 'where' => array( '0 = 1' ), 53 ); 51 54 52 55 /** … … 136 139 137 140 $defaults = array( 138 'taxonomy' => '',139 'terms' => array(),140 'field' => 'term_id',141 'operator' => 'IN',141 'taxonomy' => '', 142 'terms' => array(), 143 'field' => 'term_id', 144 'operator' => 'IN', 142 145 'include_children' => true, 143 146 ); … … 147 150 $cleaned_query['relation'] = $this->sanitize_relation( $query ); 148 151 149 // First-order clause.152 // First-order clause. 150 153 } elseif ( self::is_first_order_clause( $query ) ) { 151 154 152 $cleaned_clause = array_merge( $defaults, $query );155 $cleaned_clause = array_merge( $defaults, $query ); 153 156 $cleaned_clause['terms'] = (array) $cleaned_clause['terms']; 154 $cleaned_query[] = $cleaned_clause;157 $cleaned_query[] = $cleaned_clause; 155 158 156 159 /* … … 177 180 } 178 181 179 // Otherwise, it's a nested query, so we recurse.182 // Otherwise, it's a nested query, so we recurse. 180 183 } elseif ( is_array( $query ) ) { 181 184 $cleaned_subquery = $this->sanitize_query( $query ); … … 248 251 */ 249 252 public function get_sql( $primary_table, $primary_id_column ) { 250 $this->primary_table = $primary_table;253 $this->primary_table = $primary_table; 251 254 $this->primary_id_column = $primary_id_column; 252 255 … … 275 278 */ 276 279 $queries = $this->queries; 277 $sql = $this->get_sql_for_query( $queries );280 $sql = $this->get_sql_for_query( $queries ); 278 281 279 282 if ( ! empty( $sql['where'] ) ) { … … 315 318 $indent = ''; 316 319 for ( $i = 0; $i < $depth; $i++ ) { 317 $indent .= " ";320 $indent .= ' '; 318 321 } 319 322 … … 337 340 338 341 $sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] ); 339 // This is a subquery, so we recurse.342 // This is a subquery, so we recurse. 340 343 } else { 341 344 $clause_sql = $this->get_sql_for_query( $clause, $depth + 1 ); … … 400 403 } 401 404 402 $terms = $clause['terms'];405 $terms = $clause['terms']; 403 406 $operator = strtoupper( $clause['operator'] ); 404 407 … … 417 420 $alias = $this->find_compatible_table_alias( $clause, $parent_query ); 418 421 if ( false === $alias ) { 419 $i = count( $this->table_aliases );422 $i = count( $this->table_aliases ); 420 423 $alias = $i ? 'tt' . $i : $wpdb->term_relationships; 421 424 … … 430 433 $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)"; 431 434 } 432 433 435 434 436 $where = "$alias.term_taxonomy_id $operator ($terms)"; … … 467 469 } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) { 468 470 469 $where = $wpdb->prepare( "$operator ( 471 $where = $wpdb->prepare( 472 "$operator ( 470 473 SELECT 1 471 474 FROM $wpdb->term_relationships … … 474 477 WHERE $wpdb->term_taxonomy.taxonomy = %s 475 478 AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column 476 )", $clause['taxonomy'] ); 479 )", $clause['taxonomy'] 480 ); 477 481 478 482 } … … 562 566 $this->transform_query( $query, 'term_id' ); 563 567 564 if ( is_wp_error( $query ) ) 568 if ( is_wp_error( $query ) ) { 565 569 return; 570 } 566 571 567 572 $children = array(); 568 573 foreach ( $query['terms'] as $term ) { 569 $children = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) );574 $children = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) ); 570 575 $children[] = $term; 571 576 } … … 591 596 */ 592 597 public function transform_query( &$query, $resulting_field ) { 593 if ( empty( $query['terms'] ) ) 598 if ( empty( $query['terms'] ) ) { 594 599 return; 595 596 if ( $query['field'] == $resulting_field ) 600 } 601 602 if ( $query['field'] == $resulting_field ) { 597 603 return; 604 } 598 605 599 606 $resulting_field = sanitize_key( $resulting_field );
Note: See TracChangeset
for help on using the changeset viewer.