I’m use the code below to get the number of posts by a user and it works fine but it only includes published posts. How can I modify this code or use different code to have it include “future” post_status’s or “drafts”, for example.
<?php
$post_count = count_user_posts($curauth->ID);
echo '<p>User post count is ' . $post_count;
?>
This will do what you want:
It will include drafts, pending posts, published posts, and future posts. There are more you can set, such as trashed posts, and private posts, but that didn’t seem to follow the intent of the question. This method will include custom post types as well as the builtin post types, so additional filtering may be in order.
Docs:
WP_Query
This can be done via a custom query: Be sure to hook the query filter early enough.
Note: This solution doesn’t help more than the answer from @m0r7if3r above as the query will be run before the filter.
Note: The filter will affect all calls to
count_user_posts();
. If you don’t want that, then you’ll have to check inside the filter cb fn, if the user has a specific role or ID or whatever restriction you need.