2

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.

Any help here? Thanks in advance!

  • below answer should work perfectly for you. – sven Dec 11 '13 at 5:53
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 );
  • Same thing... still not the one I expected. Thanks for your input. – CarlosOnWeb Dec 12 '13 at 2:58
  • @CarlosOnWeb what do you expect the outcome to be? Doesn't the above solution gets you the user in descending order, orderby ID and if doesn't then check with the $meta_query – Maruti Mohanty Dec 18 '13 at 10:40
  • Hi @MarutiMohanty, I was expecting it to sort by ID in DESC order, but the result is its is sorting by first_name. Very strange. – CarlosOnWeb Dec 19 '13 at 0:54
  • Can you update your question defining $meta_query – Maruti Mohanty Dec 19 '13 at 6:08
1

If you are struggling with using get_users() and sorting the result by the value you want, you might have a look at this topic: How can I sort get_users() by any value (last_name, user defined fields and more)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.