Skip to content

Instantly share code, notes, and snippets.

@versluis
Created March 25, 2018 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save versluis/4f6b5eef20fcf960ebb46622a06979ba to your computer and use it in GitHub Desktop.
Save versluis/4f6b5eef20fcf960ebb46622a06979ba to your computer and use it in GitHub Desktop.
get total word count from all posts in WordPress
function getWordCountFromPosts () {
$count = 0;
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => 'any'
));
foreach( $posts as $post ) {
$count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID )));
}
$num = number_format_i18n( $count );
return $num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment