@mwalima,
It is a great idea indeed, to me became a need.
Looks like I got the line# wrong. At that same file look instead for the function get_user_postcount( $user_id )
and then replace the code there for this one:
/**
* Returns the postcount for a given user.
* On WPMU sites posts are counted from all blogs in field $blogs and summed up.
*
* @param int $user_id
*
* @return int post count
*/
function get_user_postcount( $user_id ) {
$total = 0;
if ( AA_is_wpmu() && ! empty( $this->blogs ) ) {
$blogs = $this->blogs;
// all blogs -> only search the user's blogs
if ( in_array( '-1', (array) $this->blogs ) ) {
$blogs = (array) $this->get_user_blogs( $user_id );
}
foreach ( $blogs as $blog_id ) {
switch_to_blog( $blog_id );
$total += count_user_posts( $user_id );
}
// reset to current blog done out side to save lot of switching
restore_current_blog();
} else {
// -------------------------------------------------------------------- Change added to consider mycpt post type ------------------------------------------
// This is a hardcode to the plugin to make it lookup for 'mycpt' post type and return the count.
global $wpdb;
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = $user_id AND post_type IN ('mycpt') and post_status = 'publish'" );
// $where = get_posts_by_author_sql( 'mycpt', true, $userid );
// $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
$regposts += count_user_posts($user_id);
$total = $regposts + $count;
// ------------------------------------------------------------------- End of change -------------------------------------------------------------------
}
return $total;
}
Replace mycpt
for whatever post type you want to consider to be counted.
Remember that on next update you’ll loose this change.
I’m glad someone agreed about this being a great idea, maybe the plugin author want to implement custom post types count for the next release.