I have create Revolution Slider which load the custom post type, Events. There are two custom fields, Event Start Date and Event End Date. I would like to display order by Start and End date. Because now only able order by Start date and if same Start date, then will order by Title.

Here is what I found from Revolution Slider website:


function modify_slider_order($query, $slider_id) {
    if($slider_id == 4) {
        $query['meta_key'] = 'event_start_date';
        $query['orderby'] = 'event_start_date';
        $query['meta_type'] = 'DATE';
        $query['order'] = 'ASC';
        return $query;
add_filter('revslider_get_posts', 'modify_slider_order', 10, 2);

However, I unable able to add array to 'orderby'. According this:


'orderby'  => array(
    'event_start_date' => 'ASC',
    'event_end_date' => 'ASC',

Can anyone give me some idea, how I change the 'orderby'?


1 Answer 1


To order by event-end date or start date, your write separate function and call them as per requirement. For example if user clicks on order by start then start function should be called.

case: 'event-start':
# your code
 $query['meta_key'] = 'event_start_date';
        $query['orderby'] = 'event_start_date';
case 'event-end':
#your code
 $query['meta_key'] = 'event_end_date';
        $query['orderby'] = 'event_end_date';

  • Hi, If I want order by both? Start date is the first priority and end date is the second. Thanks. Commented Nov 10, 2016 at 4:54
  • You will loose relation between eventStartDate - eventEndDate. If you have both of them independent then sort it individually. Like group sorting. Commented Nov 10, 2016 at 6:07
  • From the answer you reply, there is a "switch", mean user need to click. But I want to display in slider only. Can add array in square bracket? For example: code $query['orderby'] = array( 'event_start_date' => 'ASC', 'event_end_date' => 'ASC', ), ? Commented Nov 14, 2016 at 3:22
  • It depends on your coding ability. I had an idea and I shared it with you. Please go through the WP_Query. Commented Nov 14, 2016 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.