Ticket #42409: 42409.diff
| File 42409.diff, 4.8 KB (added by , 8 years ago) |
|---|
-
wp-includes/class-wp-meta-query.php
diff --git a/wp-includes/class-wp-meta-query.php b/wp-includes/class-wp-meta-query.php index af1fc11..c57d8b4 100644
a b class WP_Meta_Query { 110 110 * @type array { 111 111 * Optional. An array of first-order clause parameters, or another fully-formed meta query. 112 112 * 113 * @type string $key Meta key to filter by. 114 * @type string $value Meta value to filter by. 115 * @type string $compare MySQL operator used for comparing the $value. Accepts '=', 116 * '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 117 * 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'REGEXP', 118 * 'NOT REGEXP', 'RLIKE', 'EXISTS' or 'NOT EXISTS'. 119 * Default is 'IN' when `$value` is an array, '=' otherwise. 120 * @type string $type MySQL data type that the meta_value column will be CAST to for 121 * comparisons. Accepts 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 122 * 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', or 'UNSIGNED'. 123 * Default is 'CHAR'. 113 * @type string $key Meta key to filter by. 114 * @type string $compare_key MySQL operator used for comparing the $value. Accepts '=' and 'LIKE'. 115 * @type string $value Meta value to filter by. 116 * @type string $compare MySQL operator used for comparing the $value. Accepts '=', 117 * '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 118 * 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'REGEXP', 119 * 'NOT REGEXP', 'RLIKE', 'EXISTS' or 'NOT EXISTS'. 120 * Default is 'IN' when `$value` is an array, '=' otherwise. 121 * @type string $type MySQL data type that the meta_value column will be CAST to for 122 * comparisons. Accepts 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 123 * 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', or 'UNSIGNED'. 124 * Default is 'CHAR'. 124 125 * } 125 126 * } 126 127 */ … … class WP_Meta_Query { 236 237 * the rest of the meta_query). 237 238 */ 238 239 $primary_meta_query = array(); 239 foreach ( array( 'key', 'compare', 'type' ) as $key ) {240 foreach ( array( 'key', 'compare', 'type', 'compare_key' ) as $key ) { 240 241 if ( ! empty( $qv[ "meta_$key" ] ) ) { 241 242 $primary_meta_query[ $key ] = $qv[ "meta_$key" ]; 242 243 } … … class WP_Meta_Query { 502 503 $clause['compare'] = '='; 503 504 } 504 505 506 if ( isset( $clause['compare_key'] ) && 'LIKE' === strtoupper( $clause['compare_key'] ) ) { 507 $clause['compare_key'] = strtoupper( $clause['compare_key'] ); 508 } else { 509 $clause['compare_key'] = '='; 510 } 511 505 512 $meta_compare = $clause['compare']; 513 $meta_compare_key = $clause['compare_key']; 506 514 507 515 // First build the JOIN clause, if one is required. 508 516 $join = ''; … … class WP_Meta_Query { 517 525 if ( 'NOT EXISTS' === $meta_compare ) { 518 526 $join .= " LEFT JOIN $this->meta_table"; 519 527 $join .= $i ? " AS $alias" : ''; 520 $join .= $wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key =%s )", $clause['key'] );528 $join .= $wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key {$meta_compare_key} %s )", $clause['key'] ); 521 529 522 530 // All other JOIN clauses. 523 531 } else { … … class WP_Meta_Query { 561 569 if ( 'NOT EXISTS' === $meta_compare ) { 562 570 $sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL'; 563 571 } else { 564 $sql_chunks['where'][] = $wpdb->prepare( "$alias.meta_key =%s", trim( $clause['key'] ) );572 $sql_chunks['where'][] = $wpdb->prepare( "$alias.meta_key {$meta_compare_key} %s", trim( $clause['key'] ) ); 565 573 } 566 574 } 567 575 -
wp-includes/class-wp-query.php
diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index afc8f96..4a35545 100644
a b class WP_Query { 624 624 * @type int $m Combination YearMonth. Accepts any four-digit year and month 625 625 * numbers 1-12. Default empty. 626 626 * @type string $meta_compare Comparison operator to test the 'meta_value'. 627 * @type string $meta_compare_key Comparison operator to test the 'meta_key'. 627 628 * @type string $meta_key Custom field key. 628 629 * @type array $meta_query An associative array of WP_Meta_Query arguments. See WP_Meta_Query. 629 630 * @type string $meta_value Custom field value.