0

I have a list of events and they all have either a 'start date' or 'date'. I am trying to list the events in order using either field depending on which is filled out but am having no luck. I tried:

$args = array(
    'post_type'   => 'events',
    'meta_key' => 'date',
    'posts_per_page' => -1,
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'meta_query'=> array(
        'relation' => 'OR',
        array(
          'key' => 'date',
          'compare' => '>=',
          'value' => date("Y-m-d"),
          'type' => 'DATE'
        ),
         array(
          'key' => 'start_date',
          'compare' => '>=',
          'value' => date("Y-m-d"),
          'type' => 'DATE'
        )
    )
);

If I remove 'meta_key' => 'date' it doesn't work and as it is now this lists the 'start date' entries on top not in order then the 'date' entires on the bottom in ascending order. listing

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.