Support

Account

Home Forums ACF PRO Upcoming events are not getting displayed for time picker

Solved

Upcoming events are not getting displayed for time picker

  • We have an events custom post type and trying to display the posts as upcoming events with the below query posts.

    we have custom date and time picker fields to set the event date and time.

    it displays correct upcoming events for date, but $time clause is not working.

    $time = date("H:i:s"); // 17:16:18
    
          if (trim($session_setting) == 'upcoming') {
    
            $args = array(
    
              'post_type'=> 'livesession',
              'post_status' => 'publish',
              'posts_per_page' => 99,
              'paged' => $paged ,
              'order'     => 'ASC',
              'orderby'   => 'meta_value_num',
              'meta_query' => array(
              	'relation' => 'AND',
                  'date_clause' => array(
                    'key' => 'session_date',
                    'compare'	=> '>=',
                    'value'   => $today,
                  ),
                    'time_clause' => array(
                    'key' => 'session_time',
              	'compare'	=> '>=',
                    'value'   => $time,
    
                  ),
    
              )
            );
          }
  • You’re question is a little confusing. It appears you are using to different fields “session_date” and “session_time”, is this correct?

    If the current time is let’s say something like “14:30” and the next event starts at 8am tomorrow then the date then a
    WHERE date > today & time > now would not return that post.

    To do this you would need a nested meta query

    
    'meta_query array(
      'relation' => 'OR',
      array(
        'key' => 'session_date',
        'value' => $today,
        'compare' => '>'
      ),
      array(
        'relation' => 'AND',
        array
          'key' => 'session_date',
          'value' => $today,
          'compare' => '='
        ),
        array
          'key' => 'session_time',
          'value' => $time,
          'compare' => '>'
        ),
      )
    )
    

    I don’t know why you are using clauses, the only purpose for them is to use them in your orderby.

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

You must be logged in to reply to this topic.