How can i echo total number of posts in last year ? I‚m writing article with stats, and want to get number of posts i published last year.

There is something here, but not for last year http://perishablepress.com/press/2006/08/28/display-total-number-of-posts/ It displays only total number of all posts


All you need to do is modify the SQL query. Using the code you linked as a base:

$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND year(post_date) = 2010");
if (0 < $numposts) $numposts = number_format($numposts); 

The 'AND' I added basically gives you all the posts of 2010. Change the year accordingly

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.