diff --git wp-includes/meta.php wp-includes/meta.php
index 3caa808..f20d377 100644
|
|
class WP_Meta_Query { |
716 | 716 | elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) ) |
717 | 717 | $meta_type = 'CHAR'; |
718 | 718 | |
| 719 | $meta_value = isset( $q['value'] ) ? $q['value'] : null; |
| 720 | |
| 721 | if ( isset( $q['compare'] ) ) |
| 722 | $meta_compare = strtoupper( $q['compare'] ); |
| 723 | else |
| 724 | $meta_compare = is_array( $meta_value ) ? 'IN' : '='; |
| 725 | |
| 726 | if ( ! in_array( $meta_compare, array( |
| 727 | '=', '!=', '>', '>=', '<', '<=', |
| 728 | 'LIKE', 'NOT LIKE', |
| 729 | 'IN', 'NOT IN', |
| 730 | 'BETWEEN', 'NOT BETWEEN', |
| 731 | 'NOT EXISTS' |
| 732 | ) ) ) |
| 733 | $meta_compare = '='; |
| 734 | |
719 | 735 | $i = count( $join ); |
720 | 736 | $alias = $i ? 'mt' . $i : $meta_table; |
721 | 737 | |
722 | | // Set JOIN |
| 738 | if ( $meta_compare == 'NOT EXISTS' ) { |
| 739 | $join[$i] = "LEFT JOIN $meta_table"; |
| 740 | $join[$i] .= $i ? " AS $alias" : ''; |
| 741 | $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column AND $alias.meta_key = '$meta_key')"; |
| 742 | |
| 743 | $where[$k] = ' ' . $alias . '.' . $meta_id_column . ' IS NULL'; |
| 744 | |
| 745 | continue; |
| 746 | } |
| 747 | |
723 | 748 | $join[$i] = "INNER JOIN $meta_table"; |
724 | 749 | $join[$i] .= $i ? " AS $alias" : ''; |
725 | 750 | $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; |
… |
… |
class WP_Meta_Query { |
728 | 753 | if ( !empty( $meta_key ) ) |
729 | 754 | $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); |
730 | 755 | |
731 | | if ( !isset( $q['value'] ) ) { |
| 756 | if ( is_null( $meta_value ) ) { |
732 | 757 | if ( empty( $where[$k] ) ) |
733 | 758 | unset( $join[$i] ); |
734 | 759 | continue; |
735 | 760 | } |
736 | 761 | |
737 | | $meta_value = $q['value']; |
738 | | |
739 | | $meta_compare = is_array( $meta_value ) ? 'IN' : '='; |
740 | | if ( isset( $q['compare'] ) ) |
741 | | $meta_compare = strtoupper( $q['compare'] ); |
742 | | |
743 | | if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) |
744 | | $meta_compare = '='; |
745 | | |
746 | 762 | if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) { |
747 | 763 | if ( ! is_array( $meta_value ) ) |
748 | 764 | $meta_value = preg_split( '/[,\s]+/', $meta_value ); |