NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
---- Last modified : Sep 03 2022
Estimated reading time : 1 minute, 3 seconds - 120 words
Display number of posts per author: With this tutorial, we will create a simply query that will allow you to display the number of posts per author on your author.php template.
In order to do so, we will use the count user posts WordPress function.
<?php $user_post_count = count_user_posts( $userid , $post_type ); ?>
We will take this example and tailor it to our query. First, we need to configure global $authordata; to fetch the authors’ data. And then in a variable, we will use the author ID along with count_user_posts with our arguments.
In our example, our Post Type is called produits-listings.
<?php global $authordata; //author id $post_author = $authordata->ID; //Ici nous ajoutons notre variable author ID + nom du Pot Type echo '' . count_user_posts( $post_author, "produits-listings" ); ?>
Finally, the number of Post Type per author will be displayed within your author.php template. Nice and easy.