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

WP_User_Query to exclude users with no posts

Well I have come up with 2 solutions. Solution 1 – foreach loop and verify each user This one is based off of @GhostToast’s solution, but with updated WordPress functions //new query with default args $author_query = new WP_User_Query(); // Get the results $authors = $author_query->get_results(); if( $authors ) { foreach( $authors as $author ) … Read more

How to search for (partial match) display names of WordPress users?

Searching the main table Simply use WP_User_Query with a search argument. So if you want to search for example for a user with a keyword in his user_email or similar columns from the {$wpdb->prefix}users table, then you can do the following: $users = new WP_User_Query( array( ‘search’ => ‘*’.esc_attr( $your_search_string ).’*’, ‘search_columns’ => array( ‘user_login’, … Read more

how to get list of all users and their metadata

I think you should use wp-api functions which will do everything for you. get_users() function will get all users data just define fields which u require. get_user_meta() function will get usermeta data. $users = get_users( array( ‘fields’ => array( ‘ID’ ) ) ); foreach($users as $user){ print_r(get_user_meta ( $user->ID)); }