Skip to content

Instantly share code, notes, and snippets.

@inetbiz
Created August 14, 2019 11:36
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 inetbiz/ababdd67bdbd674f619aa8cc48966501 to your computer and use it in GitHub Desktop.
Save inetbiz/ababdd67bdbd674f619aa8cc48966501 to your computer and use it in GitHub Desktop.
WordPress Function: Number of Words in Post Content
function post_word_count() {
$count = 0;
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => array( 'post', 'page' )
));
foreach( $posts as $post ) {
$count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID )));
}
$num = number_format_i18n( $count );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment