Home Forums General Issues show posts based on date and time fields


show posts based on date and time fields

  • I found this in another post

    <?php $today = date('Ymd'); ?>
    <?php $args = array (
    'post_type' => 'games',
    'order' => 'ASC',
    'posts_per_page' => '4',
    'meta_query' => array(
    'key'		=> 'gameDate',
    'compare'	=> '>=',
    'value'		=> $today,
    ); ?>
    <h4><?php the_field('gameDate'); ?> @ <?php the_field('gameTime'); ?></h4>

    it works by only showing current dates and not any past dates. How can I get it to not show posts that have already past based on the date AND the time by 3 hours. So if today is August 5, 2015 any posts that have the gameDate field set to August 5, 2015 AND have a gameTime that is 2:00 p.m. + 3 hours…So once it becomes 5:00 p.m. on August 5, 2015 it will no longer show those.

    Here is the site the I am trying to work this if you scroll down on the right side it says “upcoming games”. If it is three hours past that “gameTime” field and the same day or past the “gameDate” field I would like it to not show that post. As it sits now if it is August 6, 2015 it won’t show any of the game posts for August 5th. I hope this makes sense and any help is greatly appreciated.

  • There really isn’t any way to do this with a single query. The reason being that if we look at the current time and compare it to a value stored in the database then every day will have times that are before and after the current time.

    ACF does not currently have a datetime field, only a date field.

    The first thing you’d need to do is to create an acf/save_post filter, in this filter you would need to create a third field that combines the date field and the time field into a single field with the format YYYY-MM-DD HH:MM:SS then you have field that you can use in a query.

    What type of field are you using for time field? Or are you using some type of date time add on field?

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘show posts based on date and time fields’ is closed to new replies.