Support

Account

Home Forums ACF PRO Upcoming events (and events that haven't passed it's end date) Reply To: Upcoming events (and events that haven't passed it's end date)

  • Hi @sanny,

    here my suggestion:

    <?php
    
                $now = date('Y-m-d H:i:s');
    
                $args = array(
                    'post_type'         => 'events',
                    'posts_per_page'    => -1,
                    'meta_query'        => array(
                        'relation'      => 'OR',
                        'date_upcoming_clause'   => array(
                            'key'       => 'event_start',
                            'compare'   => '>=',
                            'value'     => $now,
                            'type'      => 'DATETIME'
                        ),
                        array(
                            'relation'      => 'AND',
                            'date_started_clause'   => array(
                                'key'       => 'event_start',
                                'compare'   => '<=',
                                'value'     => $now,
                                'type'      => 'DATETIME'
                            ),
                            'date_end_clause'   => array(
                                'key'       => 'event_end',
                                'compare'   => '>=',
                                'value'     => $now,
                                'type'      => 'DATETIME'
                            ),
                        ),
                    ),
                    'orderby' => array(
                        'date_started_clause' => 'ASC',
                        'date_end_clause' => 'ASC',
                        'date_upcoming_clause' => 'ASC',
                    ),
                );
    
                $the_query = new WP_Query($args);
    
            ?>