2

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:

https://www.themepunch.com/faq/sort-options-post-based-sliders/

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:

http://www.billerickson.net/wp-query-sort-by-meta/

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

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

Thanks!

0

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.

switch($orderby){
case: 'event-start':
# your code
/*
 $query['meta_key'] = 'event_start_date';
        $query['orderby'] = 'event_start_date';
*/
break;
case 'event-end':
#your code
/*
 $query['meta_key'] = 'event_end_date';
        $query['orderby'] = 'event_end_date';
*/
break;

}
  • Hi, If I want order by both? Start date is the first priority and end date is the second. Thanks. – AntTeam Elvin Nov 10 '16 at 4:54
  • You will loose relation between eventStartDate - eventEndDate. If you have both of them independent then sort it individually. Like group sorting. – Third Essential Designer Nov 10 '16 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', ), ? – AntTeam Elvin Nov 14 '16 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. – Third Essential Designer Nov 14 '16 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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