[wp-trac] [WordPress Trac] #49284: WP_Meta_Query's 'compare_key' does not support 'NOT EXISTS' when used with WP_User_Query
WordPress Trac
noreply at wordpress.org
Fri Jan 24 13:30:25 UTC 2020
#49284: WP_Meta_Query's 'compare_key' does not support 'NOT EXISTS' when used with
WP_User_Query
--------------------------+-----------------------------
Reporter: gikaragia | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 5.3.2
Severity: normal | Keywords: has-patch
Focuses: |
--------------------------+-----------------------------
The following snippet:
{{{#!php
<?php
function test_get_users() {
$meta_query = array(
'relation' => 'OR',
array(
'key' => 'learner_calculated_version',
'value' => '3',
'compare' => '!=',
),
array(
'key' => 'learner_calculated_version',
'compare_key' => 'NOT EXISTS',
)
);
$user_args = array(
'meta_query' => $meta_query
);
$users = get_users( $user_args );
global $wpdb;
print_r($wpdb->queries);
}
add_action('admin_init', 'test_get_users');
}}}
produces the following error:
{{{
WordPress database error: [Unknown column 'mt1.post_ID' in 'where clause']
SELECT DISTINCT wp_users.* FROM wp_users INNER JOIN wp_usermeta ON (
wp_users.ID = wp_usermeta.user_id ) INNER JOIN wp_usermeta AS mt1 ON (
wp_users.ID = mt1.user_id ) WHERE 1=1 AND ( ( wp_usermeta.meta_key =
'learner_calculated_version' AND wp_usermeta.meta_value != '3' ) OR NOT
EXISTS (SELECT 1 FROM wp_postmeta mt2 WHERE mt2.post_ID = mt1.post_ID AND
mt2.meta_key = 'learner_calculated_version' LIMIT 1) ) ORDER BY user_login
ASC
}}}
The issue is that in the subquery, wp_postmeta is queried instead of
wp_usermeta.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49284>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list