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

Method #1: The pre_user_query hook: There are not many filters available, but you can try the pre_user_query hook: // Add filter: add_action( ‘pre_user_query’, ‘wpse_filter_by_reg_date’ ); // Query: $query = new WP_User_Query( $args ); // Remove filter: remove_action( ‘pre_user_query’, ‘wpse_filter_by_reg_date’ ); where the filter callback is: /** * Filter WP_User_Query by user_registered date * * @see … Read more

WP_User_Query Custom Field meta_query with Date clause

You can set the type of the data in your meta_query. Unfortunately, you can only use the comparison BETWEEN if your date is in the format YYYYMMDD. So to see the users for one year, you would have to set your metaquery like this: $usersByCompanyArgs = new WP_User_Query( array( ‘fields’ => ‘all_with_meta’, ‘orderby’ => ‘bhaa_runner_dateofrenewal’, … Read more

WP_User_Query with meta_query array relation ‘OR’

From the Codex: Multiple custom user fields handling $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, 0 => array( ‘key’ => ‘country’, ‘value’ => ‘Israel’, ‘compare’ => ‘=’ ), 1 => array( ‘key’ => ‘age’, ‘value’ => array( 20, 30 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) ) ); Try adding the 0 … Read more

How to display next and prev pagination links with WP_User_Query?

I’m not aware of any generic helper – all the post-related navigation functions seem to be tied into the global WP_Query instance. The only real useful function at your disposal is get_pagenum_link: $paged = max( 1, get_query_var( ‘paged’ ) ); if ( $number * $paged < $wp_user_query->total_users ) { printf( ‘<a href=”https://wordpress.stackexchange.com/questions/267947/%s”>Next</a>’, get_pagenum_link( $paged + … Read more

Sort WP_User_Query by meta_key value with pre_user_query

As written, this is unlikely to do anything. If you add a couple of var_dumps like this: function sort_by_member_number( $vars ) { var_dump($vars); if ( isset( $vars->query_vars[‘orderby’] ) && ‘member-number’ == $vars->query_vars[‘orderby’] ) { $vars = array_merge( $vars->query_vars, array( ‘meta_key’ => ‘arcc_member_number’ ) ); } var_dump($vars); return $vars; } add_filter( ‘pre_user_query’, ‘sort_by_member_number’ ); You will … Read more

WP CLI – show users whose ID is larger than given ID

One way to work with existing WP-CLI commands is through the WP_CLI::runcommand(). Here are two examples how we can filter an existing WP-CLI command, namely the wp user list command based on WP_User_Query and it’s pre_user_query hook: Run a custom script in WP-CLI Let’s write our script.php file with: <?php add_action( ‘pre_user_query’, ‘wpse_pre_user_query’ ); WP_CLI::runcommand( … Read more

Searching user meta using WP_User_Query

Try this: $yoursearchquery = ‘This is my search’; $users = new WP_User_Query(array( ‘search’ => $yoursearchquery, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘shoe_size’, ‘value’ => $yoursearchquery, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘shoe_color’, ‘value’ => $search_operation, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘shoe_maker’, ‘value’ => $yoursearchquery, ‘compare’ => ‘=’ ) ) … Read more