From 55609b863e63a2e2e586bce913dfe3d2618a5e0c Mon Sep 17 00:00:00 2001 From: Jon Cave 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: https://develop.svn.wordpress.org/trunk@18825 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 3da7542ada..fadd377696 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 );