Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix order by start date if end date is empty for ACF fields

Discussion in 'Misc WordPress Requests' started by bhujelshashi, Nov 2, 2017.

  1. bhujelshashi

    Guest

    order by start date if end date is empty for ACF fields, by bhujelshashi

    I have a page which lists the upcoming events and past events. The start date is mandatory but end date can be empty. I want to order by events based on end date and use start date if the end date is empty. My query looks like this:
    $args = array(
    ‘post_type’ => ‘events_entries’,
    ‘post_status’ => ‘publish’,
    ‘meta_query’ => array(
    ‘relation’ => ‘OR’,
    ‘start_date’ => array(
    ‘key’ => ‘date’,
    ‘compare’ => ‘EXISTS’,
    ),
    ‘end_date’ => array(
    ‘key’ => ‘end_date’,
    ‘compare’ => ‘EXISTS’,
    ),
    ),
    ‘orderby’ => [‘start_date’ => ‘DESC’, ‘end_date’ => ‘DESC’],
    ‘paged’ => $paged
    );

    but it doesn’t work. Thank you in advance for your help.

    order by start date if end date is empty for ACF fields
     
    #1

Share This Page

Web Hosting