WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/count many users posts

Description

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.

Usage

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

Parameters

$users
(array) (required) List of ID values of the users whose post counts should be retrieved.
Default: None
$post_type
(string) (optional) Name of the post type
Default: null
$public_only
(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

(array) 
Amount of posts each user has written.

Example

Default Usage

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

<?php
$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.

Related

count_user_posts, get_posts_by_author_sql

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