The get_the_author_posts() WordPress PHP function retrieves the number of posts by the author of the current post.
Usage
$author_post_count = get_the_author_posts();
Output: 4250
(assuming the author has published 4,250 posts)
Parameters
None
More information
See WordPress Developer Resources: get_the_author_posts()
Examples
Display author’s name and post count
Display the author’s name and number of posts in a paragraph.
<p> <?php the_author(); ?> has blogged <?php echo number_format_i18n( get_the_author_posts() ); ?> posts </p>
Output: “Harriett Smith has blogged 4,250 posts.”
Show post count in author bio
Display the author’s bio along with their number of posts.
<div class="author-bio"> <p><?php echo get_the_author_meta('description'); ?></p> <p>Published <?php echo get_the_author_posts(); ?> posts</p> </div>
Customize author’s post count message
Customize the message displayed based on the number of posts.
$author_posts = get_the_author_posts(); if ($author_posts > 1000) { echo "Wow! " . the_author() . " has written over 1,000 posts!"; } else { echo the_author() . " has written " . $author_posts . " posts."; }
Display author’s post count in a table
Show the author’s post count in an HTML table.
<table> <tr> <th>Author</th> <th>Number of Posts</th> </tr> <tr> <td><?php the_author(); ?></td> <td><?php echo get_the_author_posts(); ?></td> </tr> </table>
Compare post counts of two authors
Compare the post counts of two authors and display a message.
$author1_post_count = get_the_author_posts(); // Assuming inside author1's loop $author2_post_count = get_the_author_posts(); // Assuming inside author2's loop if ($author1_post_count > $author2_post_count) { echo "Author 1 has written more posts than Author 2."; } elseif ($author1_post_count < $author2_post_count) { echo "Author 2 has written more posts than Author 1."; } else { echo "Both authors have written the same number of posts."; }