Display How Many Post Have Been Published Today at Your Blog

by Hiroshi on November 14, 2008

in Hacks, WordPress

In this tutorial we will display how many posts have been posted today. For blogs which publish posts more than one each day, this tutorial can help them displaying today’s stats about published posts.

Get today’s date, and then create another variable containing today’s date – 24 hours.
Then, we send SQL request to the database by using the $wpdb->get_var() method.

//Today's date
$today = date("Y-m-d H:i:s");
//Today - 1 day
$daysago = date("Y-m-d H:i:s",strtotime(date('Y-m-j H:i:s')) - (1 * 24 * 60 * 60));
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_date BETWEEN '$daysago' AND '$today'");
if ($numposts >0) 
    echo $numposts.' posts published today';
    echo "No posts published today".

You can use this script anywhere in your blog, lets say; in sidebar.

Related Posts

Previous post:

Next post: