Changeset 17746
- Timestamp:
- 04/28/2011 03:02:16 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/meta.php
r17699 r17746 477 477 $meta_id_column = esc_sql( $type . '_id' ); 478 478 479 $join = '';479 $join = array(); 480 480 $where = array(); 481 $i = 0; 481 482 482 foreach ( $this->queries as $k => $q ) { 483 483 $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; … … 493 493 $meta_type = 'CHAR'; 494 494 495 if ( empty( $meta_key ) && empty( $meta_value ) ) 496 continue; 497 495 $i = count( $join ); 498 496 $alias = $i ? 'mt' . $i : $meta_table; 499 497 500 $join .= "\nINNER JOIN $meta_table";501 $join .= $i ? " AS $alias" : '';502 $join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";503 504 $i++; 505 498 // Set JOIN 499 $join[$i] = "INNER JOIN $meta_table"; 500 $join[$i] .= $i ? " AS $alias" : ''; 501 $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; 502 503 $where[$k] = ''; 506 504 if ( !empty( $meta_key ) ) 507 505 $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); 508 506 509 if ( !isset( $q['value'] ) ) 507 if ( !isset( $q['value'] ) ) { 508 if ( empty( $where[$k] ) ) 509 unset( $join[$i] ); 510 510 continue; 511 } 512 511 513 $meta_value = $q['value']; 512 514 … … 515 517 $meta_value = preg_split( '/[,\s]+/', $meta_value ); 516 518 517 if ( empty( $meta_value ) ) 519 if ( empty( $meta_value ) ) { 520 unset( $join[$i] ); 518 521 continue; 522 } 519 523 } else { 520 524 $meta_value = trim( $meta_value ); … … 533 537 } 534 538 535 $where[$k] = ' (' . $where[$k] . $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string})", $meta_value ); 536 } 537 $where = ' AND (' . implode( " {$this->relation} ", $where ) . ' )'; 539 if ( ! empty( $where[$k] ) ) 540 $where[$k] .= ' AND '; 541 542 $where[$k] = ' (' . $where[$k] . $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string})", $meta_value ); 543 } 544 545 $where = array_filter( $where ); 546 547 if ( empty( $where ) ) 548 $where = ''; 549 else 550 $where = ' AND (' . implode( "\n{$this->relation} ", $where ) . ' )'; 551 552 $join = implode( "\n", $join ); 553 if ( ! empty( $join ) ) 554 $join = ' ' . $join; 538 555 539 556 return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $this->queries, $type, $primary_table, $primary_id_column, $context ) ); 540 557 } 541 542 558 } 543 559
Note: See TracChangeset
for help on using the changeset viewer.