From 5eeea164efdaa966386768bbd3c268e0aed14211 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sun, 14 Dec 2014 19:01:26 +0000 Subject: [PATCH] In `WP_Meta_Query`, interpret 'value' correctly when used with EXISTS/NOT EXISTS. As in earlier versions, EXISTS with a value is equivalent to '=', while NOT EXISTS should always ignore 'value'. Props barrykooij. Fixes #30681 for trunk. Built from https://develop.svn.wordpress.org/trunk@30846 git-svn-id: http://core.svn.wordpress.org/trunk@30836 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 44fb7d2ddf..1637413d78 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -1419,6 +1419,17 @@ class WP_Meta_Query { $where = $wpdb->prepare( '%s', $meta_value ); break; + // EXISTS with a value is interpreted as '='. + case 'EXISTS' : + $meta_compare = '='; + $where = $wpdb->prepare( '%s', $meta_value ); + break; + + // 'value' is ignored for NOT EXISTS. + case 'NOT EXISTS' : + $where = ''; + break; + default : $where = $wpdb->prepare( '%s', $meta_value ); break;