How to order custom user list columns by datetime?

I think you could simplify this a lot by using the pre_get_users hook, instead of working directly with the complicated SQL within the pre_user_query hook. Try something like: add_action( ‘pre_get_users’, function( \WP_User_Query $q ) { $qv = &$q->query_vars; if( isset( $qv[‘orderby’] ) && ‘test_date’ === $qv[‘orderby’] ) { // Custom meta query $qv[‘meta_query’] = [ … Read more

Wp_user_query search by meta_key not returning any results

You’re setting two different meta_key fields to check on: ‘course’, and ‘clinic’. Try doing it with just one like so: $args = array( ‘orderby’ => ‘display_name’, ‘fields’ => ‘all’, ‘search’ => $search, ‘meta_query’ => array( array( ‘key’ => ‘clinic’, ‘value’ => $search, ‘compare’ => ‘LIKE’ ) ) ); What your current query is doing is … Read more

How to order users alphabetically by name? in plugin UPME

Diana you must change line of code in this array $args = array( ‘exclude’=> $admin_users_list, ‘number’ => $limit, ‘orderby’ => ‘registered’, ‘order’ => ‘desc’, ‘meta_query’ => array( ‘relation’ => ‘AND’, 0 => array( ‘key’ => ‘upme_user_profile_status’, ‘value’ => ‘ACTIVE’, ‘compare’ => ‘=’ ), 1 => array( ‘key’ => ‘upme_approval_status’, ‘value’ => ‘ACTIVE’, ‘compare’ => ‘=’ … Read more

Loop 1 user randomly

I found a realy great solition here. !! It is a function that kindof ‘adds’ ‘orderby’ => ‘rand’ as a parameter. What it does it that when someone uses that parameter, the function will query the database using regular MySQL, where random is always possible 🙂 The function: // put this in your functions.php add_filter(‘pre_user_query’, … Read more

Get Sticky User in user loop based on user role

If you read the code (in version 4.5.2 on line 164-173) you will see that orderby can be an array of values, coupled with order. So you could modify $args like this: $args = array( ‘orderby’ => array( array (‘sticky’ => ‘DESC’), array (‘registered’ => ‘DESC’)), ‘fields’ => ‘all_with_meta’, ); Note that I know nothing … Read more

WP User Query with meta queries

Actually, I think your code says Where min_price >= $price and max_price <= $price. Try to switch the operands, like here: array( ‘key’ => ‘min_price’, ‘value’ => $price, ‘compare’ => ‘<=’, ‘type’ => ‘NUMERIC’ ), array( ‘key’ => ‘max_price’, ‘value’ => $price, ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ), It works for 10.000 and 20.000 … Read more