Automattic / Automattic/co-authors-plus

filter_count_user_posts not running on get_usernumposts filter

Open
#231 2 comments 0 reactions 0 assignees View on GitHub
status: needs investigation
Dominant language
PHP
Stars
322
Forks
216
Avg merge
7h 50m
Merged PRs (30d)
65

Description

I am fetching the total number of posts created by users using the following function:

```
function count_user_posts_by_type( $userid, $post_type = 'post' ) {
global $wpdb;
$where = get_posts_by_author_sql( $post_type, true, $userid );
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
return apply_filters( 'get_usernumposts', $count, $userid );
}
```

The issue is that it is not counting the Co-authored posts for the custom post type.

More information :
I have created a page template which runs a WP_User loop for a user role. For each user I need to fetch the total number of custom post types created by the user for which the above function is called for every user.

Now, the function `filter_count_user_posts` should run on `get_usernumposts` filter, but it seems it is not working as expected. Any help/suggestions are welcome.

Contributor guide

Open the contributing guide

Research direction

Start by tracing filter_count_user_posts and the get_usernumposts filter in the plugin, then reproduce the custom post type case described in the issue. Confirm how co-authored posts are counted and whether the filter runs; done means the user post count includes the relevant co-authored posts.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend, content
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.