Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/count many users posts


Returns the post counts for a list of user IDs. This is an O(n) operation, so it is preferred over count_user_posts() any time more than a single count is needed.


 <?php count_many_users_posts$users$post_type$public_only ); ?> 


(array) (required) List of ID values of the users whose post counts should be retrieved.
Default: None
(string) (optional) Name of the post type
Default: null
(string) (optional) Bypasses checking capabilities of current user (False) or returns posts only if they can be viewed by current user (True).
Default: False

Return Value

Amount of posts each user has written.


Default Usage

The call to count_many_users_posts returns the number of posts made by each user.

$users = array(1, 3, 9, 10);
$counts = count_many_users_posts($users);
echo 'Posts made by user 3: ' . $counts[3];
Posts made by user 3: 143

Change Log

  • 3.5.0: Added the public_only parameter
  • Since: 3.0.0

Source File

count_many_users_posts() is located in wp-includes/user.php.


count_user_posts, get_posts_by_author_sql

See also index of Function Reference and index of Template Tags.