Created
February 3, 2015 19:45
-
-
Save AramZS/4bf62ae51616e5a4da1b to your computer and use it in GitHub Desktop.
pf_ive_read
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
// 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