WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to display the "number of posts in the last 24 hours"? (11 posts)

  1. Anonymous
    Unregistered
    Posted 6 years ago #

    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.

  2. noname1
    Member
    Posted 6 years ago #

    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.

  3. Anonymous
    Unregistered
    Posted 6 years ago #

    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?

  4. noname1
    Member
    Posted 6 years ago #

  5. iridiax
    Member
    Posted 6 years ago #

    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; ?>

  6. Anonymous
    Unregistered
    Posted 6 years ago #

    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?

  7. Anonymous
    Unregistered
    Posted 6 years ago #

    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; ?>

  8. Define83
    Member
    Posted 6 years ago #

    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;
  9. Anonymous
    Unregistered
    Posted 6 years ago #

    That worked! Thanks Define83!

  10. obsessedwithfilm
    Member
    Posted 5 years ago #

    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.

  11. GHenrik
    Member
    Posted 5 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic