Skip to content

Instantly share code, notes, and snippets.

@jamesrwhite
Created December 19, 2011 14:14
Show Gist options
  • Save jamesrwhite/1497414 to your computer and use it in GitHub Desktop.
Save jamesrwhite/1497414 to your computer and use it in GitHub Desktop.
bbPress - Get an users post count
<?php
/*
*
* Get Author Post Count
*
* @param: (int) user id
*
*/
function bbp_get_author_post_count($author_id = NULL) {
if( $author_id !== NULL ) {
$author_id = (int) mysql_real_escape_string($author_id);
$query = mysql_query("
SELECT count(ID) FROM wp_posts
WHERE post_author = " . $author_id . "
AND (
post_type = 'topic' OR post_type = 'reply'
)
AND (
post_status = 'publish' OR post_status = 'closed'
)
LIMIT 1;
");
$post_count = mysql_fetch_row($query);
return $post_count[0];
}
return 0;
}
// Usage
global $current_user;
get_currentuserinfo();
echo 'Post Count: ' . bbp_get_author_post_count($current_user->ID);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment