Pagination not working on custom query

The pagination functions work off of the main query, so you’d need to use pre_get_posts instead of creating a new query for them to work. But, you’re using WP_User_Query, so the standard pagination system will never work for you. You’re going to have to ‘roll your own’ pagination system here, and generate your own URLs … Read more

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

Yes possible, just tell WordPress to use RAND() SQL sorting when passing rand in orderby parameter: add_action( “pre_user_query”, function( $query ) { if( “rand” == $query->query_vars[“orderby”] ) { $query->query_orderby = str_replace( “user_login”, “RAND()”, $query->query_orderby ); } }); Now you can use: $users = get_users( array( ‘meta_key’ => ‘last_name’, ‘orderby’ => ‘rand’, ‘number’ => 3 // … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)