• I’m using the code below to create a list of authors on my site. It’s all working except that it’s putting the total number of posts for the entire site next to each author’s name instead of the number of posts that they’ve written.

    I can’t figure out what I need to change in the code to make it just display the number of posts for each author. Can anyone help?

    Thanks!

    <?php
    $display_admins = true;
    $order_by = ‘display_name’; // ‘nicename’, ’email’, ‘url’, ‘registered’, ‘display_name’, or ‘post_count’
    $role = ”; // ‘subscriber’, ‘contributor’, ‘editor’, ‘author’ – leave blank for ‘all’
    $avatar_size = 32;
    $hide_empty = true; // hides authors with zero posts

    if(!empty($display_admins)) {
    $blogusers = get_users(‘orderby=’.$order_by.’&role=’.$role);
    } else {
    $admins = get_users(‘role=administrator’);
    $exclude = array();
    foreach($admins as $ad) {
    $exclude[] = $ad->ID;
    }
    $exclude = implode(‘,’, $exclude);
    $blogusers = get_users(‘exclude=’.$exclude.’&orderby=’.$order_by.’&role=’.$role);
    }
    $authors = array();
    foreach ($blogusers as $bloguser) {
    $user = get_userdata($bloguser->ID);
    $numposts = count_user_posts($user->ID);
    if(!empty($hide_empty)) {
    $numposts = count_user_posts($user->ID);
    if($numposts < 1) continue;
    }
    $user->numposts = $numposts;
    $authors[] = (array) $user;
    }

    echo ‘<ul class=”contributors”>’;
    foreach($authors as $author) {
    $display_name = $author[‘data’]->display_name;
    $avatar = get_avatar($author[‘ID’], $avatar_size);
    $author_profile_url = get_author_posts_url($author[‘ID’]);
    $user = get_userdata($user_id);
    $numposts = count_user_posts($user->ID);

    echo ‘

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Author post count is for whole site instead of by author’ is closed to new replies.