Get post count for the user by their post type in wordpress and bbpress 2.0

We use count_user_posts function to get count of the total post for the user whose ID is passed to this function. We can use this function as:

 <?php count_user_posts( $userid ); ?>

You can find this function in wp-includes/user.php.

But if we want to get the post count by their post type ( such as Post, Revision etc.), then you can use simple function derived from count_user_posts(), with post_type support added as second parameter. You can write this function in wp-includes/user.php.

function count_user_posts_by_type($userid, $post_type) 
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);

How to use this function:

You can use this function by passing $userid and $post_type like as:

<?php echo 'Number of Article: '. count_user_posts_by_type($user_ID,'post');?>

How to use this function in bbpress 2:

If you are using bbpress 2.0 in your wordpress blog and you want to display number of the post, thread and reply on the user profile page. Then you can use the count_user_posts_by_type() in userddetails.php in your bbpress plugin directory like as :

<div id="author-description">
    <h1><?php printf( __( 'About %s', 'bbpress' ), bbp_get_displayed_user_field( 'display_name' ) ); ?></h1>
			<?php echo bbp_get_displayed_user_field( 'description' ); ?>
		</div><!-- #author-description	-->
<div style="margin-top:10px;margin-bottom:=10px;font-size:11px;margin-left:70px;">
<li>Name:<?php echo bbp_get_displayed_user_field( 'display_name' ); ?></li>
<li><?php echo 'Number of Article: ' . count_user_posts_by_type( bbp_get_displayed_user_field( 'ID'),'post'); ?></li>
<li><?php echo 'Number of Thread started: ' . count_user_posts_by_type( bbp_get_displayed_user_field( 'ID'),'topic'); ?></li>
<li><?php echo 'Number of Reply: ' . count_user_posts_by_type( bbp_get_displayed_user_field( 'ID'),'reply'); ?></li>