Add NOT LIKE/BETWEEN/IN. props AaronCampbell, fixes #9124.

git-svn-id: http://svn.automattic.com/wordpress/trunk@15755 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-10-08 02:27:22 +00:00
parent 9228d56df5
commit 137796ddbd

View File

@ -551,7 +551,7 @@ class WP_Object_Query {
* - 'key' string The meta key
* - 'value' string|array The meta value
* - 'compare' (optional) string How to compare the key to the value.
* Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'IN', 'BETWEEN'.
* Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
* Default: '='
* - 'type' string (optional) The type of the value.
* Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.
@ -636,7 +636,7 @@ class WP_Object_Query {
$meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'IN', 'BETWEEN' ) ) )
if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
$meta_compare = '=';
if ( 'NUMERIC' == $meta_type )
@ -658,7 +658,7 @@ class WP_Object_Query {
if ( !empty( $meta_key ) )
$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
if ( in_array( $meta_compare, array( 'IN', 'BETWEEN' ) ) ) {
if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
if ( ! is_array( $meta_value ) )
$meta_value = preg_split( '/[,\s]+/', $meta_value );
} else {
@ -668,14 +668,14 @@ class WP_Object_Query {
if ( empty( $meta_value ) )
continue;
if ( 'IN' == $meta_compare ) {
if ( 'IN' == substr( $meta_compare, -2) ) {
$meta_field_types = substr( str_repeat( ',%s', count( $meta_value ) ), 1 );
$meta_compare_string = "($meta_field_types)";
unset( $meta_field_types );
} elseif ( 'BETWEEN' == $meta_compare ) {
} elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) {
$meta_value = array_slice( $meta_value, 0, 2 );
$meta_compare_string = '%s AND %s';
} elseif ( 'LIKE' == $meta_compare ) {
} elseif ( 'LIKE' == substr( $meta_compare, -4 ) ) {
$meta_value = '%' . like_escape( $meta_value ) . '%';
$meta_compare_string = '%s';
} else {