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
This commit is contained in:
duck_ 2011-09-29 22:10:56 +00:00
parent 33c150d3de
commit fda510aca1
1 changed files with 7 additions and 4 deletions

View File

@ -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 );