From 24ac7c4ac5e93e3d6726a7b15d57e14d7f6e8102 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Fri, 5 Jul 2013 16:40:46 +0000 Subject: [PATCH] Prevent invalid queries in certain empty-array-passing meta_query cases. fixes #22096. props wonderboymusic. git-svn-id: http://core.svn.wordpress.org/trunk@24563 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 367eb6b95d..976fd51ce9 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -678,7 +678,7 @@ class WP_Meta_Query { } // WP_Query sets 'meta_value' = '' by default - if ( isset( $qv[ 'meta_value' ] ) && '' !== $qv[ 'meta_value' ] ) + if ( isset( $qv[ 'meta_value' ] ) && '' !== $qv[ 'meta_value' ] && ( ! is_array( $qv[ 'meta_value' ] ) || $qv[ 'meta_value' ] ) ) $meta_query[0]['value'] = $qv[ 'meta_value' ]; if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) { @@ -714,6 +714,14 @@ class WP_Meta_Query { $key_only_queries = array(); $queries = array(); + // Split out the queries with empty arrays as value + foreach ( $this->queries as $k => $q ) { + if ( is_array( $q['value'] ) && empty( $q['value'] ) ) { + $key_only_queries[$k] = $q; + unset( $this->queries[$k] ); + } + } + // Split out the meta_key only queries (we can only do this for OR) if ( 'OR' == $this->relation ) { foreach ( $this->queries as $k => $q ) {