Support

Account

Home Forums General Issues Ordering/Filtering wp_query using ACF Date field Reply To: Ordering/Filtering wp_query using ACF Date field

  • More like this

    
    <?php
    $recent_args = array(
      'post_type'  => 'event',
      'meta_query' => array(
        'relation' => 'AND',
        array(
          'key'     => 'end_date',
          'value'   => $date_2,
          'compare' => '<',
        ),
        array(
          'relation' => 'OR',
          array(
            'key'    => 'end_date',
            'compare'   => 'BETWEEN',
            'type'     => 'DATE',
            'value'   => array($date_1, $date_2),
          ),
          // if no end date has been set use start date
          array(
          'key'       => 'date',
          'compare'   => 'BETWEEN',
          'type'     => 'DATE',
          'value'   => array($date_1, $date_2),
          ),
        ),
      ),
      'orderby'     => 'meta_value_num',
      'order'          => 'DESC',
      'nopaging'       => true
    );
    ?>