How to display next and prev pagination links with WP_User_Query?

Looking through the pagination functions available in WordPress, most seem to be associated with posts. paginate_links() seems to be the only function which will work with WP_User_Query. However, when I use that I get numbered pagination: echo paginate_links( array( ‘base’ => get_pagenum_link( 1 ) . ‘%_%’, ‘current’ => max( 1, get_query_var( ‘paged’ ) ), ‘format’ … Read more

Get users in query and limit user output to five in random order

In the footer.php I show all the authors of my blog with the following code: $args = array( ‘meta_key’ => ‘last_name’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’ ); // Create the WP_User_Query object $wp_user_query = new WP_User_Query( $args ); $wp_user_query->query_orderby = str_replace( ‘user_login’, ‘wp_usermeta.meta_value’, $wp_user_query->query_orderby ); // Get the results $authors = $wp_user_query->get_results(); Is it … Read more

How to get a list of all users registered before a given date?

I was expecting to be able to do something like the following which I thought would return all users that have registered before a given date: $args = array( ‘post_type’ => ‘post’, ‘date_query’ => array( array( ‘before’ => current_time( ‘mysql’ ) ) ) ); $query = new WP_User_Query( $args ); However, unlike WP_Query, WP_User_Query doesn’t … Read more

Searching user meta using WP_User_Query

Per the documentation for WP_User_Query, there is an available search parameter. It looks something like this: $users = new WP_User_Query(array( ‘search’ => ‘This is my search’ )); You can even set the columns in the database that are searched against using the “search_columns” parameter like so: $users = new WP_User_Query(array( ‘search’ => ‘This is my … Read more

each_connected in wp_user_query with Scribu’s Posts to Posts Plugin – Alternative method? [closed]

Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for WordPress Development Stack Exchange. Closed 7 years ago. Improve this question I have been using Scribu’s Posts to Posts plugin for some time, and it has served me well. I have read … Read more

What is the most efficient way to search users by their display name?

Initially I thought I’d use get_users() but it turned out it doesn’t support the display_name field. Then I’ve read about using WP_User_Query, but when I do it always exhausts the allowed memory size of 134217728 bytes. When I remove the memory limit this part of the page doesn’t even try to load. Now I’m thinking … Read more

Check if WP_User_Query ‘include’ is empty

This is my code: $args = array ( ‘order’ => ‘DESC’, ‘include’ => get_user_meta($author->ID, ‘the_following_users’, true) ); $wp_user_query = new WP_User_Query( $args ); $users = $wp_user_query->get_results(); if ( ! empty( $users ) ) { foreach ( $users as $user ) { // Get users } } else { echo ‘Error.’; } The user meta ‘the_users’ … Read more

pre_user_query meta_query admin user list

I’m attempting to use pre_user_query’ to change the query to include somemeta_query` variables. My goal is to only display users in the user list if they share a common meta_value with the current logged in user… function modify_user_list($query){ $user = wp_get_current_user(); if( ! current_user_can( ‘edit_user’ ) ) return $query; $user_id = $user->ID; $user_branch_number = get_user_meta($user_id, … Read more