I'd like to display posts made in the last 24 hours.
So far I have this:
<?php
$current_year = date('Y');
$current_month = date('m');
$current_day = date('j');
query_posts("showposts=10&year=$current_year&monthnum=$current_month&day=$current_day");
?>
This way I display posts made today but not from the last 24 hours.
What should I use to get what I want?
apostaganha2
Member
Posted 3 years ago #
function filter_where($where = '') {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-24 hours')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
lobos55
Member
Posted 3 years ago #
is there a way to achieve similar in wp_query?
artesea
Member
Posted 2 years ago #
shouldn't the date bit include H:i:s to ensure that it shows posts only from the last 24 hours and not from yesterday morning onwards?
function filter_where($where = '') {
$where .= " AND post_date > '" . date('Y-m-d H:i:s', strtotime('-24 hours')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);