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
This commit is contained in:
Jon Cave 2011-09-29 22:10:56 +00:00
parent 76251c5287
commit 55609b863e
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 );