Created
March 25, 2018 00:26
-
-
Save versluis/4f6b5eef20fcf960ebb46622a06979ba to your computer and use it in GitHub Desktop.
get total word count from all posts in WordPress
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
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