Ticket #27272: 27272_meta2.diff
File 27272_meta2.diff, 2.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-meta-query.php
587 587 $meta_value = trim( $meta_value ); 588 588 } 589 589 590 switch ( $meta_type ) { 591 case 'SIGNED': 592 $cast_string = '%d'; 593 break; 594 case 'UNSIGNED': 595 $cast_string = '%u'; 596 break; 597 default: 598 $cast_string = '%s'; 599 break; 600 } 601 590 602 switch ( $meta_compare ) { 591 603 case 'IN' : 592 604 case 'NOT IN' : 593 $meta_compare_string = '(' . substr( str_repeat( ', %s', count( $meta_value ) ), 1 ) . ')';605 $meta_compare_string = '(' . substr( str_repeat( ',' . $cast_string, count( $meta_value ) ), 1 ) . ')'; 594 606 $where = $wpdb->prepare( $meta_compare_string, $meta_value ); 595 607 break; 596 608 … … 597 609 case 'BETWEEN' : 598 610 case 'NOT BETWEEN' : 599 611 $meta_value = array_slice( $meta_value, 0, 2 ); 600 $where = $wpdb->prepare( '%s AND %s', $meta_value );612 $where = $wpdb->prepare( $cast_string . ' AND ' . $cast_string, $meta_value ); 601 613 break; 602 614 603 615 case 'LIKE' : 604 616 case 'NOT LIKE' : 605 617 $meta_value = '%' . $wpdb->esc_like( $meta_value ) . '%'; 606 $where = $wpdb->prepare( '%s', $meta_value );618 $where = $wpdb->prepare( $cast_string, $meta_value ); 607 619 break; 608 620 609 621 // EXISTS with a value is interpreted as '='. 610 622 case 'EXISTS' : 611 623 $meta_compare = '='; 612 $where = $wpdb->prepare( '%s', $meta_value );624 $where = $wpdb->prepare( $cast_string, $meta_value ); 613 625 break; 614 626 615 627 // 'value' is ignored for NOT EXISTS. … … 618 630 break; 619 631 620 632 default : 621 $where = $wpdb->prepare( '%s', $meta_value );633 $where = $wpdb->prepare( $cast_string, $meta_value ); 622 634 break; 623 635 624 636 } 625 637 626 if ( $where ) {638 if ( $where !== '' ) { 627 639 $sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}"; 628 640 } 629 641 }