Support

Account

Home Forums General Issues Query posts where end and/or start date are in the past Reply To: Query posts where end and/or start date are in the past

  • I tried above solutions, unfortunately, none worked out for me. When I used ‘OR’ in the first wp_query argument, it hung up the page.

    I ended up accidentally writing this code that solved the issue for me:

    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key'     => 'date_start',
            'value'   => date( 'Ymd' ),
            'compare' => '=',
            'type'    => 'date'
        ),
        array(
            'relation' => 'AND',
            array(
                'key'     => 'date_start',
                'value'   => date( 'Ymd' ),
                'compare' => '<=',
                'type'    => 'date'
            ),
            array(
                'key'     => 'date_end',
                'value'   => date( 'Ymd' ),
                'compare' => '>=',
                'type'    => 'date'
            ),
        ),
    )

    Gist for description: https://gist.github.com/842c14baeb42d33ce90d1d1bf7a5de68

    Not sure why the previous code didn’t work for me as the logic seems perfectly fine. I guess it’s just way to complex to be a query 🙂