Don’t know how efficient this is:
<?php
//Get users and count of posts put into array $uc, sort array by post count descending, loop through array and echo user info
$uc=array();
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$post_count = get_usernumposts($bloguser->user_id);
$uc[$bloguser->user_id]=$post_count;
}
arsort($uc); //use asort($uc) if ascending by post count is desired
foreach ($uc as $key => $value) {
$user = get_userdata($key);
$author_posts_url = get_author_posts_url($key);
$post_count = $value;
echo 'User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname . ' number of posts:' . $post_count . ' author posts url:' . $author_posts_url .'';
}
}
?>
[Edit – note that it is descending using arsort]
Thread Starter
c
(@igneous)
couldnt get that to work, does anyone else have any other thoughts?
MichaelH you’re a life saver!! The code above works GREAT!! I’ve been searching for a way to do this for hours. Have you figured out by any chance if the code is efficient? Are there many db queries taking place? (I have no idea, just asking). Again, many thanks.
igneous, give it another try. Just copy paste it into your code and then change the echo line to show the user info! You can use this list to get the user information (name, url, etc) you need.
Hi MichaelH
Forgive my English
The code works for me, but I need only show 10 or 15 authors by the amount of post they made.
How can I restrict that the code only show me 10 or 15 authors ordered by $post_count?
Thanks
Looks ok to me..
Average time, 100 iterations (just to benchmark)..
0.00684