Skip to content

Instantly share code, notes, and snippets.

@AramZS
Created February 3, 2015 19:45
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 AramZS/4bf62ae51616e5a4da1b to your computer and use it in GitHub Desktop.
Save AramZS/4bf62ae51616e5a4da1b to your computer and use it in GitHub Desktop.
pf_ive_read
// Add Shortcode
function pf_total_wordcount_shortcode() {
$wc = 0;
$c = 0;
$the_query = new WP_Query(
array(
'nopaging' => true,
'date_query' => array(
'column' => 'post_date_gmt',
'after' => '30 days ago',
)
)
);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$content = get_post_field( 'post_content', get_the_ID() );
$word_count = str_word_count( strip_tags( $content ) );
$wc = $wc+$word_count;
$c++;
endwhile;
wp_reset_postdata();
?><p><?php echo 'I\'ve read '.$wc.' words across '.$c.' posts in the past 30 days.'; ?></p><?php
else :
?><p><?php _e( 'I\'ve read nothing in the past 30 days.' ); ?></p><?php
endif;
}
add_shortcode( 'pf_total_wordcount', 'pf_total_wordcount_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment