get_users() ORDER BY Not Working

I’m not sure where the problem lies, but the code below just doesn’t have the effect of ordering by ID in descending order.

$args['role'] = 'subscriber';
$args['orderby'] = 'ID';
$args['order'] = 'DESC';
$args['fields'] = 'all_with_meta';      
$args['meta_query'] = $meta_query; // $meta_query is an array specified someplace above

$my_users = get_users( $args );

I’m aware that by default, WordPress is sorting by ‘login’ and in ASC order.

Read More

Any help here? Thanks in advance!

Related posts

2 comments

  1. Try putting the args into an array.

    $args = array(
        'role'       => 'subscriber',
        'orderby'    => 'ID',
        'order'      => 'DESC',
        'fields'     => 'all_with_meta',
        'meta_query' => $meta_query
    );
    
    $my_users = get_users( $args );
    

Comments are closed.