From 12ff8a31c36150eaf24a5437c13b99bed570583b 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: https://develop.svn.wordpress.org/trunk@24563 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 ) {