[wp-trac] [WordPress Trac] #23849: Unexpected results when running WP_User_Query with role and meta_query

WordPress Trac noreply at wordpress.org
Thu Apr 17 22:16:39 UTC 2014


#23849: Unexpected results when running WP_User_Query with role and meta_query
------------------------------------+------------------------------
 Reporter:  layotte                 |       Owner:
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  Users                   |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  dev-feedback has-patch  |     Focuses:
------------------------------------+------------------------------
Changes (by jdgrimes):

 * keywords:  dev-feedback => dev-feedback has-patch


Comment:

 I just came upon this problem as well. The issue is always present on
 multisite even when no role query is explicitly set, because on multisite
 it adds `"AND mt1.meta_key = 'wptests_capabilities'"` to all of the
 queries (I assume so that only confirmed users are queried).

 [attachment:23849.diff] fixes both issues, and includes unit tests
 demonstrating the problems. All the patch does is check if the meta query
 is using `'relation' => 'OR'`, and if so it uses a second `WP_Meta_Query`
 object to get the SQL for the caps query, instead of just appending the
 conditions to the main meta query. As a result the caps query is always an
 `AND`, instead of sometimes being unintentionally changed to an `OR`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/23849#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list