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