How to list users by rating?
Hello,
I want top list TOP 5 users for their ratings. How can I do it?
For example I use to list TOP 5 users by their post count this code:
<?php
global $wpdb;
$top_authors = $wpdb->get_results("
SELECT u.ID, count(post_author) as posts FROM {$wpdb->posts} as p
LEFT JOIN {$wpdb->users} as u ON p.post_author = u.ID
WHERE p.post_status = ‘publish’
AND p.post_type = ‘post’
GROUP by p.post_author
ORDER by posts DESC
LIMIT 0,5
");
if( !empty( $top_authors ) ) {
echo '<ul style="text-align: center;">';
foreach( $top_authors as $key => $author ) {
echo get_avatar( $author->ID , 45 ) . '<li style="margin-bottom: 15px;"><a href="' . get_author_posts_url( $author->ID ) . '" style="text-decoration: none;color: rgb(54, 116, 157);text-transform: capitalize;font-weight: 600;font-size: 16px;">' . get_the_author_meta( 'user_nicename' , $author->ID ) . '</a></li>';
}
echo '</ul>';
}
?>