Show author post count in sidebar – Variable

To get the number of posts published by a user i found the solution was to call count_user_posts(), passing in the appropriate user id.

<?php echo 'Posts made: ' . count_user_posts( get_the_author_meta('ID') ); ?>

In translation ready form.

<?php printf( 'Posts made: %d', count_user_posts( get_the_author_meta('ID') ) ); ?>

Storage in a variable.

<?php $user_post_count = count_user_posts( get_the_author_meta('ID') ); ?>

Leave a Comment