WordPress.org

Ready to get started?Download WordPress

Forums

Post loops from a specific interval of time (3 posts)

  1. alvarols
    Member
    Posted 1 year ago #

    I'm doing a newspaper website, and I need to make a loop with the news of the day. ie, in the loop must have the post of the current day, but there is an issue.

    The day ends at 12:00AM, but my client will upload the news at 8:00 AM. So, I need to show the last day posts until 8:00 from the next day. It's like day starts at 8:00 AM and not 12:00 AM.

    How can I do this loop?

    Thanks

  2. esmi
    Forum Moderator
    Posted 1 year ago #

  3. alvarols
    Member
    Posted 1 year ago #

    Yes but I don't know exactly how I have to do. I am checking this code.

    // Create a new filtering function that will add our where clause to the query
    function filter_where( $where = '' ) {
    // posts 30 to 60 days old
    $where .= " AND post_date >= '" . date('Y-m-d', strtotime('-60 days')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('-30 days')) . "'";
    return $where;
    }

    add_filter( 'posts_where', 'filter_where' );
    $query = new WP_Query( $query_string );
    remove_filter( 'posts_where', 'filter_where' );

    I can put something like, show me the posts published today from 8:00. But it won't work from 12:00 AM to 7:59 AM the next day before my client publishs the new posts at 8:00 AM.

Topic Closed

This topic has been closed to new replies.

About this Topic