Support » Fixing WordPress » How to display the “number of posts in the last 24 hours”?

  • Resolved Anonymous

    I have a client who wants to display, in plain text, the number of posts in the last 24 hours.

    Does anyone know how to do this?

    I’ve seen it on a number of blogs while googling for an answer. I think this is a fairly simple task but I can’t find any documentation or plugin on the subject.

    Thanks in advance.

Viewing 10 replies - 1 through 10 (of 10 total)
  • you’ll have to use number of posts displayed per date, then just display today. You’ll need to call the calendar in a certain way.

    Thanks for the reply. I’m sorry if this is a dumb question, but what do you mean by “use number of posts displayed per date”? What template tag or other WP tag calls that function?

    This code below prints out the total number of posts (it should work with your older WordPress). You might be able to modify it with post_date to do what you want.

    <?php $numpost = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'"); echo $numpost; ?>

    Thank you so much Iridiax.

    I don’t have the PHP knowledge, unfortunately, to implement the use of “post_date” into your code to get it to do what I want.

    Does anyone know how to do this using Iridiax’s code?

    Would the code look something like this?

    <?php $numpost = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_date < 'code-for-24-hour-period'"); echo $numpost; ?>

    Hi steve, you can try something like

    $allDay = date('Y-m-d H:i:s', strtotime('-1 day'));
    
    $numpost = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_date > '$allDay'"); echo $numpost;

    That worked! Thanks Define83!

    Is there a way I can modify define’s code to seperate each day’s set of posts. I want to set it up so that on loading the site shows only posts made today, but have a hidden div below it when clicked you can see yesterdays post also.

    Hello! I’m completely new to all website and php development.
    How do you use the example from define83 to display a simple post count number from all time posts when you enter the url to it?

    And where in the wordpress folders system do you include the .php file?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to display the “number of posts in the last 24 hours”?’ is closed to new replies.