Searching users with WP_List_Table plugin

Brian is correct. By changing the form to use get instead of post and then using $_REQUEST to fetch it should work, and is for me. // Fetch, prepare, sort, and filter our data. if( isset( $_REQUEST [“s”] ) ){ // Form that displays the table and also contains the search_box() <form id=”table-class-filter” method=”get” class=”table-class-admin-form”>

User appears twice in a WP_User_Query

Try this for kicks… Solution 1 Note: Does not work with WP_User_Query (?) add_filter(‘posts_distinct’, ‘user_meta_query_distinct’); //your query here… remove_filter(‘posts_distinct’, ‘user_meta_query_distinct’); function user_meta_query_distinct() { return “DISTINCT”; } Solution 2 Can you try adding ‘relation’ => ‘OR’ to your meta_query: $user_query = new WP_User_Query( array( ‘role’ => ‘member’, ‘orderby’ => ‘registered’, ‘order’ => ‘DESC’, ‘meta_query’ => array( … Read more

How to order WP_User_Query results to match the order of an array of user IDs?

Updated: The WP_User_Query class, in WordPress 4.1+, supports it with : ‘orderby’ => ‘include’ Since WordPress 4.7 there’s also support for: ‘orderby’ => ‘login__in’ and ‘orderby’ => ‘nicename__in’ So we no longer need to implement it through a filter, like we did here below. Previous Answer: I wonder if this works for you: add_action( ‘pre_user_query’, … Read more

WP_User_Query users by registered date

You can simply use the date_query parameter on the user registration date: $args = array ( ‘role’ => ‘subscriber’, ‘date_query’ => array( array( ‘after’ => ‘2010-01-13 00:00:00’, ‘inclusive’ => true, ), ), ); $user_query = new WP_User_Query( $args ); This part of the WP_User_Query source code, makes it possible: // Date queries are allowed for … Read more

How to search display_name column when using WP_User_Query

You can try this: /** * Add support for the “display_name” search column in WP_User_Query * * @see http://wordpress.stackexchange.com/a/166369/26350 */ add_filter( ‘user_search_columns’, function( $search_columns ) { $search_columns[] = ‘display_name’; return $search_columns; } ); where we use the user_search_columns filter to modify the available search columns. So what fields can we use with this filter? Here’s … Read more

Query users by custom taxonomy and user role

Apparently there is no core implementation of ‘tax_query’ in WP_User_Query yet. Check the ticket here for more info –> https://core.trac.wordpress.org/ticket/31383 Nevertheless there is an alternative way using get_objects_in_term $taxonomy = ‘shop-category’; $users = get_objects_in_term( $term_id, $taxonomy ); if(!empty($users)){ // WP_User_Query arguments $args = array ( ‘role’ => ‘shop_manager’, ‘order’ => ‘DESC’, ‘orderby’ => ‘user_registered’, ‘include’ … Read more

List users by last name in WP_User_Query

There is a better way to do this as of WordPress version 3.7. Use the WordPress property meta_key to select the last name property and then orderby => meta_value with an ascending order. <?php $args = array( ‘meta_key’ => ‘last_name’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’ ); $user_query = new WP_User_Query( $args ); if ( … Read more