[wp-trac] [WordPress Trac] #62041: WP_User_Query with compare_key always get 0 user

WordPress Trac noreply at wordpress.org
Thu Sep 12 04:14:11 UTC 2024


#62041: WP_User_Query with compare_key always get 0 user
--------------------------+-----------------------------
 Reporter:  fantasyworld  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  6.6.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The user query alway get 0 user.
 {{{
 $args = [
     'meta_query' => [
         'relation' => 'OR',
         [
             'key' => 'nickname',
             'value' => 'test',
             'compare' => '!=',
         ],
         [
             'key' => 'nickname',
             'compare_key' => 'NOT EXISTS',
         ],
     ]
 ];
 $user_search = new WP_User_Query($args);
 }}}

 It is because the real query sql try to user `postmeta` table in user
 query.

 {{{
 SELECT DISTINCT SQL_CALC_FOUND_ROWS wp_users.ID
     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 = 'nickname' AND wp_usermeta.meta_value !=
 'test' )
         OR
         NOT EXISTS (SELECT 1 FROM wp_postmeta mt2 WHERE mt2.post_ID =
 mt1.post_ID AND mt2.meta_key = 'nickname' LIMIT 1)
     )
 ORDER BY user_login ASC
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62041>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list