I need to display the number of posts that were added TODAY

I found this one that will show number of all posts but I need only last day

$total = wp_count_posts()->publish;
echo 'Total Posts: ' . $total;

I've a felling that it's very easy but I coudn't any script that will work :(

Thank You in advance, Peter


You can use WP_Query like this:

// we get the date for today
$today = getdate();
//we set the variables, i am ignoring sticky posts so they dont get counted
$args = array(
    'ignore_sticky_posts' => 1,
    'posts_per_page' => -1, //all posts 
    'date_query' => array(
            'year'  => $today["year"],
            'month' => $today["mon"],
            'day'   => $today["mday"],

//we create the query
$today_posts = new WP_Query( $args );
//the result already has a property with the number of posts returned
$count = $today_posts->post_count;
//show it
echo $count;
  • kk it wasn't that easy hehe Thank You it's working great:) – user262404 Mar 15 '17 at 19:16
  • i updated the answer, i added 'posts_per_page' => -1 to display all posts, it can be done with 'nopaging' => true too – David Lee Mar 15 '17 at 21:04
  • I figured it by myself using nopaging but Thanks again for your help – user262404 Mar 16 '17 at 14:59

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.