Support

Account

Home Forums ACF PRO WP_Query based on ACF values (get values before loop) Reply To: WP_Query based on ACF values (get values before loop)

  • Hi @juxprose

    maybe you can use this query instead?

    $args = array(
        'post_type' => 'events',
        'post_status' => 'publish',
        'posts_per_page' => '-1',
        'meta_query' => array(
            'relation' => 'OR', 
            array(
                'relation' => 'AND', // if no end date
                array(
                    'key' => events_date_end,
                    'compare' => '=',
                    'value' => '',
                ),
                array(
                    'key' => events_date_start,
                    'compare' => '>=',
                    'value' => $date,
                ),
            ),
            array(
                'relation' => 'AND', //if have end date
                array(
                    'key' => events_date_end,
                    'compare' => '!=',
                    'value' => '',
                ),
                array(
                    'key' => events_date_end,
                    'compare' => '>=',
                    'value' => $date,
                ),
            ),
        ),
        'meta_key' => 'events_date_start',
        'orderby' => 'meta_value',
        'order' => 'ASC'
    );

    Keep in mind that I haven’t tested it yet. Please fix it if you find some errors.

    I hope this helps.