I'm trying to get a list of authors on my site & their total posts.
All of this code is working, except the $count_posts($author->ID) part in the loop.
I think there may also be issues with my array for get_users - as I'm trying to more parts to the array.
function all_authors_list() {
$authors = get_users(array(
'role' => 'subscriber',
'orderby' => 'post_count',
'order' => 'DESC',
'number' => '20',
)
);
$authors = $count_posts;
$count_posts = wp_count_posts('page');
$published_posts = $count_posts->publish;
foreach($authors as $author) {
echo '<div class="author-name">' . $author->first_name . ' ' . $author->last_name . '</div>';
echo '<div class="author-post-count">' . $count_posts($author->ID) . '</div>';
}
}
So the final output should be something like:
John Smith
20
Patricia Long
35
...etc.
Write this below code in your post loop:
<p><?php the_author(); ?> has <?php echo number_format_i18n( get_the_author_posts() ); ?>
posts</p>
Reference: http://codex.wordpress.org/Function_Reference/get_the_author_posts
You can possibly use count_many_users_posts
to achieve that.
Basically you will get User's ID in to an array that is generated by the $authors
and you can use that user ID in count_many_users_posts
.
There is three parameters in count_many_users_posts
function and you can use $post_type
parameter to get only pages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.