Function: count_user_posts

count_user_posts( integer $userid, array | string $post_type, boolean $public_only )

Number of posts user has written.

Parameters

Name Type(s) Default Value Description
$userid integer

User ID.

$post_type array | string 'post'

Optional. Single post type or array of post types to count the number of posts for. Default 'post'.

$public_only boolean false

Optional. Whether to only return counts for public posts. Default false.

Returns

string

Number of posts the user has written in this post type.

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.