[wp-trac] [WordPress Trac] #41719: Malformed User Search results

WordPress Trac noreply at wordpress.org
Wed Aug 23 22:17:01 UTC 2017


#41719: Malformed User Search results
--------------------------+-----------------------------
 Reporter:  navepilif     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Users         |    Version:  4.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 There is a logic bug with the User Search WP_User_Query. (Users > All
 Users > "Search Users" (in top-right corner)).

 The SQL that is generated looks something like this:

 {{{
 SELECT SQL_CALC_FOUND_ROWS wp_users.ID
   FROM wp_users
  INNER JOIN wp_usermeta
     ON ( wp_users.ID = wp_usermeta.user_id )
  WHERE (
            1=1 AND
            (
                user_login    LIKE '%Search Term%' OR
                user_url      LIKE '%Search Term%' OR
                user_email    LIKE '%Search Term%' OR
                user_nicename LIKE '%Search Term%' OR
                display_name  LIKE '%Search Term%'
            )
  )
  ORDER BY user_login ASC LIMIT 0, 20;
 }}}


 However, such a query is not guaranteed to return unique user IDs. It just
 so "happens" to work right now. The more correct query adds the DISTINCT
 keyword:


 {{{
 SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_users.ID
  ...
 }}}


 Modifying the query in certain situations results in duplicate user IDs
 being returned. One example, of many such modifications that could be
 made, can be seen in the Better User Search plugin on line
 https://github.com/wp-plugins/better-user-search/blob/master/better-user-
 search.php#L200.

 As is, this is currently breaking pagination and sometimes displaying
 redundant users as you flip through the pages. (See attached screenshot.
 My pagination is set to 20, and I have 100 matching users on my system).

 [[Image()]]

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


More information about the wp-trac mailing list