Forums

Display posts from the last 24 hours (5 posts)

  1. zglows
    Member
    Posted 3 years ago #

    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?

  2. zglows
    Member
    Posted 3 years ago #

    Is this even possible?

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

  4. lobos55
    Member
    Posted 3 years ago #

    is there a way to achieve similar in wp_query?

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

Topic Closed

This topic has been closed to new replies.

About this Topic