Quantcast
Channel: Question and Answer » wpdb
Viewing all articles
Browse latest Browse all 44

How to get top 10 user is based on user meta value

$
0
0

I’m trying to get top 10 users in my wordpress blog based on user meta value.

I’ve tried few methods & finally able to get just top one user using below wpdb query. But clueless, how we can get top 10 users.

$top10alltime = $wpdb->get_row( "SELECT MAX( CAST( meta_value AS UNSIGNED ) ) AS top_user FROM $wpdb->usermeta WHERE meta_key = 'alltimeusers'" ); 

echo $top10alltime->top_user;

Is $wpdb is right for this purpose? Or is there any other solution to get this done? using WP_User_Query?

I’ve tried something with WP_User_Query.

foreach ( $users as $var => $order ) {
$query->query(
    array(
        'count_total' => false,
        'meta_key' => 'todayuserclicks',
        'orderby' => 'meta_value',
        'fields' => 'ID',
        'number' => 10,
        'order' => $order,
    )
);

I can’t get this done after this .. how can we do this?


Viewing all articles
Browse latest Browse all 44

Trending Articles