Changeset 15724 for trunk/wp-includes/classes.php
- Timestamp:
- 10/04/2010 09:37:08 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r15723 r15724 590 590 foreach ( $this->meta_query as $q ) { 591 591 $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; 592 $meta_value = isset( $q['value'] ) ? trim( $q['value'] ) : ''; 593 $meta_compare = isset( $q['compare'] ) ? $q['compare'] : '='; 594 595 if ( !in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'like' ) ) ) 592 $meta_value = isset( $q['value'] ) ? $q['value'] : ''; 593 $meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '='; 594 $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR'; 595 596 if ( !in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'IN', 'BETWEEN' ) ) ) 596 597 $meta_compare = '='; 598 599 if ( 'STRING' == $meta_type ) 600 $meta_type = 'CHAR'; 601 602 if ( 'NUMERIC' == $meta_type ) 603 $meta_type = 'SIGNED'; 604 605 if ( !in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) ) 606 $meta_type = 'CHAR'; 597 607 598 608 if ( empty( $meta_key ) && empty( $meta_value ) ) … … 610 620 $where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key ); 611 621 622 if ( in_array( $meta_compare, array( 'IN', 'BETWEEN' ) ) ) { 623 if ( !is_array( $meta_value ) ) 624 $meta_value = preg_split( '/[,\s]+/', $meta_value ); 625 } else { 626 $meta_value = trim( $meta_value ); 627 } 628 612 629 if ( empty( $meta_value ) ) 613 630 continue; 614 631 615 if ( 'like' == $meta_compare ) { 616 $where .= $wpdb->prepare( " AND $alias.meta_value LIKE %s", '%' . like_escape( $meta_value ) . '%' ); 632 if ( 'IN' == $meta_compare ) { 633 $meta_field_types = substr( str_repeat( ',%s', count( $meta_value ) ), 1 ); 634 $meta_compare_string = "($meta_field_types)"; 635 unset( $meta_field_types ); 636 } elseif ( 'BETWEEN' == $meta_compare ) { 637 $meta_value = array_slice( $meta_value, 0, 2 ); 638 $meta_compare_string = '%s AND %s'; 639 } elseif ( 'LIKE' == $meta_compare ) { 640 $meta_value = '%' . like_escape( $meta_value ) . '%'; 641 $meta_compare_string = '%s'; 617 642 } else { 618 $ where .= $wpdb->prepare( " AND $alias.meta_value $meta_compare %s", $meta_value );643 $meta_compare_string = '%s'; 619 644 } 645 $where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value ); 646 unset($meta_compare_string); 620 647 } 621 648
Note: See TracChangeset
for help on using the changeset viewer.