Skip to content

Instantly share code, notes, and snippets.

@versluis
Created March 25, 2018 00:33
Show Gist options
  • Save versluis/bf74b1f411133dac50e47abc0b5f2d7b to your computer and use it in GitHub Desktop.
Save versluis/bf74b1f411133dac50e47abc0b5f2d7b to your computer and use it in GitHub Desktop.
get word count from comments written by the current user in WordPress
function getWordCountCommentsCurrentUser() {
$count = 0;
$user_id = get_current_user_id();
$comments = get_comments( array(
'user_id' => $user_id
));
foreach( $comments as $comment ) {
$count += str_word_count( $comment->comment_content );
}
return $count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment