From fda510aca1bc963c6075c0c362a64835ff26c614 Mon Sep 17 00:00:00 2001 From: duck_ Date: Thu, 29 Sep 2011 22:10:56 +0000 Subject: [PATCH] Automatically set 'compare' => 'IN' in WP_Meta_Query::get_sql() when the meta value is an array. Props ldebrouwer, SergeyBiryukov. Fixes #16829. git-svn-id: http://svn.automattic.com/wordpress/trunk@18825 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 3da7542ad..fadd37769 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -709,12 +709,8 @@ class WP_Meta_Query { foreach ( $this->queries as $k => $q ) { $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; - $meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '='; $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR'; - if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) - $meta_compare = '='; - if ( 'NUMERIC' == $meta_type ) $meta_type = 'SIGNED'; elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) ) @@ -740,6 +736,13 @@ class WP_Meta_Query { $meta_value = $q['value']; + $meta_compare = is_array( $meta_value ) ? 'IN' : '='; + if ( isset( $q['compare'] ) ) + $meta_compare = strtoupper( $q['compare'] ); + + if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) + $meta_compare = '='; + if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) { if ( ! is_array( $meta_value ) ) $meta_value = preg_split( '/[,\s]+/', $meta_value );