Support

Account

Home Forums General Issues Display upcoming events up to current hour

Helping

Display upcoming events up to current hour

  • I am using ACF with the Date/Time Picker extension. Currently, I’m using the date picker that’s in the core plugin and the Date/Time picker to only use the time function as to not go through all of our current events, there’s a lot, and update the date fields.

    As of now, we’re displaying all upcoming events to the day. What I’m trying to do is display all upcoming events to the day as well as the current hour. So if there’s an event at 7pm and it’s 8pm, that event will not display.

    Can anyone recommend a way for me to achieve this?

    Here is my current query:

    $todays_date = current_time('Ymd');
    	$args = array(
        		'post_type' => 'events',
    		'post_status' => 'publish',
        		'posts_per_page' => '10',
        		'meta_query' => array(
            		'relation' => 'AND',
            		'date_clause' => array(
                		'key' => 'event_date_begins',
                		'compare' => '>=',
                		'value' => $todays_date,
            		),
            	'time_clause' => array(
                	'key' => 'event_start_time',
                	'compare' => 'EXISTS',
            ),
        ),
        'orderby' => array(
            'date_clause' => 'ASC',
            'time_clause' => 'ASC',
        ),
  • Hi @svsdnb

    I believe Date/Time Picker add-on uses a timestamp to save the date in the database. If you use it, I believe you can do it like this:

    $today_timestamp = time();
    
    ...
    
    'meta_query' => array(
        'relation' => 'AND',
        'date_clause' => array(
            'key' => 'event_start_time',
            'compare' => '>=',
            'value' => $today_timestamp,
        ),

    If you use ACF’s new date time picker field, I believe you can do it like this:

    $today_datetime = date('Y-m-d H:i:s');
    
    ...
    
    'meta_query' => array(
        'relation' => 'AND',
        'date_clause' => array(
            'key' => 'event_date_begins',
            'compare' => '>=',
            'value' => $today_datetime,
            'type' => 'DATETIME',
        ),

    I hope this helps 🙂

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

The topic ‘Display upcoming events up to current hour’ is closed to new replies.