List authors by posts? (6 posts)

  1. c
    Posted 7 years ago #

    I want to list authors by the amount of posts they made, is this possible? I couldnt see a way to do it in the docs

  2. MichaelH
    Posted 7 years ago #

    Don't know how efficient this is:

    //Get users and count of posts put into array $uc, sort array by post count descending, loop through array and echo user info
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $post_count = get_usernumposts($bloguser->user_id);
      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]

  3. c
    Posted 7 years ago #

    couldnt get that to work, does anyone else have any other thoughts?

  4. mpiftex
    Posted 7 years ago #

    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.

  5. djdiego88
    Posted 6 years ago #

    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?


  6. Mark / t31os

    Posted 6 years ago #

    Looks ok to me..
    Average time, 100 iterations (just to benchmark)..


Topic Closed

This topic has been closed to new replies.

About this Topic