Support » Plugin: Event Organiser » How to change sort order of shortcode [eo_events] from ASC to DESC

  • Dear Stephen,

    I use the following shortcode in a WordPress page to integrate a list of events of a certain category:
    [eo_events event_category="XYZ"]

    The list should show newest events on top and older events at the bottom (DESC). The default behaviour is to sort the results ASC.

    I was able to adapt the order of the results in the event archive by adding the following filter to my theme’s function.php, but it does not affect the sort order of the results from the eo_events shortcode.

    add_filter('posts_orderby','my_eventorganiser_sort_events',20,2);
    function my_eventorganiser_sort_events( $orderby, $query ){
        global $wpdb;
        if( empty($query->query_vars['orderby']) ){
            if( eventorganiser_is_event_query( $query, true ) ){
                $orderby = " {$wpdb->eo_events}.StartDate DESC, {$wpdb->eo_events}.StartTime DESC";
            }
        }
        return $orderby;
    }

    What would be the correct filter to add for the shortcode?

    Thanks in advance,

    Matthieu

    https://wordpress.org/plugins/event-organiser/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    Hi Matthieu,

    The default order is chronological, but you may want to hide past events as otherwise past events will appear at the top.

    If you reverse the default order you’ll end up with the ‘futuremost’ events at the top, which doesn’t really make sense.

    In any case, to change the order you need to use the order parameter and, owing to a longstanding bug, the orderby parameter:

    [eo_events event_category="XYZ" order="DESC" orderby="eventstart"]

    But as I say, I think what you really want is:

    [eo_events event_category="XYZ" event_start_after="now"]
    Thread Starter Matthieu-P. Schapranow

    (@theschappy)

    Dear Stephen,

    Perfect, works like charm.

    PS.: I do not want to hide past events as the plugin is used to organize group meetings and older events contain presented materials, e.g. slide decks or notes.

    Cheers,

    Matthieu

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to change sort order of shortcode [eo_events] from ASC to DESC’ is closed to new replies.