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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter zglows

    (@zglows)

    Is this even possible?

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

    is there a way to achieve similar in wp_query?

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display posts from the last 24 hours’ is closed to new replies.