0

I am trying to build a meta_query which will return all posts that have at least one of their datepicker value greater than today. If the value of the datepicker is null then I don't want to be returned. Here is what I have tried:

$args  = ['post_type'=> 'cp_course', 'numberposts' => 8,'orderby' => 'menuorder', 'order' => 'ASC',
         'meta_query' =>
            array(
                'relation' => 'OR',
                array(
                    'relation' => 'AND',
                    array(
                        'key' => 'period_a_start',
                        'compare' => '>',
                        'type' => 'DATE',
                        'value' => $today,
                    ),
                    array(
                        'key' => 'period_a_start',
                        'compare' => '!=',
                        'value' => '',
                    ),
                ),              
                array(
                    'relation' => 'AND',
                    array(
                        'key' => 'period_b_start',
                        'compare' => '>',
                        'type' => 'DATE',
                        'value' => $today,
                    ),
                    array(
                        'key' => 'period_b_start',
                        'compare' => '!=',
                        'value' => '',
                    ),
                ),
                array(
                    'relation' => 'AND',
                    array(
                        'key' => 'period_c_start',
                        'compare' => '>',
                        'type' => 'DATE',
                        'value' => $today,
                    ),
                    array(
                        'key' => 'period_c_start',
                        'compare' => '!=',
                        'value' => '',
                    ),
                ),
                array(
                    'relation' => 'AND',
                    array(
                        'key' => 'period_d_start',
                        'compare' => '>',
                        'type' => 'DATE',
                        'value' => $today,
                    ),
                    array(
                        'key' => 'period_d_start',
                        'compare' => '!=',
                        'value' => '',
                    ),
                ),
            ),];

But when I run it, it goes in to an infinite loop. How I can fix that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.