Example 1 — Basic count
Print the number of posts.
<?php the_author_posts(); ?> How It Works
- WordPress counts posts by the current author.
- The number is printed.
- Nothing else is added.

In WordPress, the_author_posts() prints the number of posts written by the author of the current post. Use it inside The Loop.
It counts posts of the same post type as the current post. To get the number as a value, use get_the_author_posts().
Call it with no arguments where you want the number to appear.
the_author_posts();
$count = get_the_author_posts(); | Call | What it does |
|---|---|
the_author_posts() | Prints the number of posts by the current post author. |
get_the_author_posts() | Returns the same number so you can use it in code. |
No echo is needed for the_author_posts().
the_author_posts(): void | Parameter | Description |
|---|---|
| None | This function takes no arguments. It reads the author of the current post. |
| Return Value | Description |
|---|---|
| void (prints to the page) | The function prints a number. Its twin get_the_author_posts() returns it as an integer. |
Three short theme examples. Each one has a sample output.
Print the number of posts.
<?php the_author_posts(); ?> Use the number inside a short message.
<p>
<?php the_author(); ?> has written
<?php the_author_posts(); ?> posts.
</p> the_author() prints the name.the_author_posts() prints the count.Return the number when you want to use if.
<?php
$count = get_the_author_posts();
if ( $count > 10 ) {
echo 'Top author';
}
?> get_the_author_posts() returns the count.if checks if it is more than 10.the_author_posts(), because it only prints.Build a select box of users for forms and admin screens.
9 people found this page helpful