[wp-trac] [WordPress Trac] #36624: Add nicename__in and nicename__not_in to WP_User_Query

WordPress Trac noreply at wordpress.org
Thu Apr 21 20:01:26 UTC 2016


#36624: Add nicename__in and nicename__not_in to WP_User_Query
-----------------------------+-------------------------------------
 Reporter:  johnjamesjacoby  |      Owner:
     Type:  enhancement      |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Users            |    Version:
 Severity:  normal           |   Keywords:  needs-patch 2nd-opinion
  Focuses:                   |
-----------------------------+-------------------------------------
 I have a need to query for multiple users by their nicenames. Right now, I
 do something like this:

 {{{
 // Get usernames
 $usernames = some_function_to_get_usernames();

 // Loop through usernames and link to profiles
 foreach ( (array) $usernames as $username ) {

         // Skip if username does not exist or user is not active
         $user = get_user_by( 'slug', $username );
         if ( empty( $user->ID ) ) {
                 continue;
         }

         // Some things...
 }
 }}}

 It would be great if `WP_User_Query` worked in the following ways:

 `__in`:

 {{{
 $users = new WP_User_Query( array(
         'nicename__in' => array( 'admin', 'john', 'paul' )
 ) );
 }}}


 `__not_in`:

 {{{
 $users = new WP_User_Query( array(
         'nicename__not_in' => array( 'admin' )
 ) );
 }}}

 ----

 The "nice" thing about this, is `user_nicename` is an indexed column, so
 these queries should be speedy and internally optimized by MySQL.

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


More information about the wp-trac mailing list