I’m having troubles with getting a post count (total) for users.
I think it has to do the get_the_author_posts, which should give me the users total post – expressed as a number.
function all_authors_list() {
$authors = get_users(array(
'role' => 'subscriber',
'orderby' => 'post_count',
'order' => 'DESC',
'number' => '20',
)
);
foreach($authors as $author) {
echo '<li class="author-name">' . $author->first_name . ' ' . $author->last_name . '</li>';
echo '<div class="author-post-count">' . $author->get_the_author_posts() . '</div>';
}
}
All of this works, except the author post count line.
Any ideas?
(thanks in advance 🙂
Kindly try this one :
echo '<div class="author-post-count">' . get_the_author_posts() . '</div>';
instead of
echo '<div class="author-post-count">' . $author->get_the_author_posts() . '</div>';
And you can also try this one :
echo '<div class="author-post-count">' . count_user_posts(your_author_id) . '</div>';
Hope this helps..
You can use
count_user_posts()
to get the post count for a user.See: http://codex.wordpress.org/Function_Reference/count_user_posts
In your case: