Created
December 19, 2011 14:14
-
-
Save jamesrwhite/1497414 to your computer and use it in GitHub Desktop.
bbPress - Get an users post count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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