Each user in system has meta key called points
I need to get top 10 users (highest points)
How I can do this query ?
Should I use get_users()
with $args
OR native query
1 Answer
You can use get_users()
with meta_key
and order by meta value, descending.
Example:
$user_args = array(
'meta_key' => 'points',
'number' => 10,
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$top_users = get_users($user_args);
NOTE: Support for
meta_value_num
is available only from version 4.2