Anonymous
Unregistered
Posted 4 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.
greyisgood
Member
Posted 4 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.
Anonymous
Unregistered
Posted 4 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?
greyisgood
Member
Posted 4 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; ?>
Anonymous
Unregistered
Posted 4 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?
Anonymous
Unregistered
Posted 4 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; ?>
Define83
Member
Posted 4 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;
Anonymous
Unregistered
Posted 4 years ago #
That worked! Thanks Define83!
obsessedwithfilm
Member
Posted 4 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.
GHenrik
Member
Posted 4 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?