WordPress.org

Support

Support » Plugins and Hacks » Hacks » Changing event sort order

Changing event sort order

  • slyphidine
    Member

    @slyphidine

    I saw a few questions about this. I answered it on the original question, but thought it might be hard to find. So here it is:

    I was able to change the sort order by adding some code to the php file. Within the simple-events-calendar.php file find the following block:

    function eventquery($label,$age,$range,$limit) {
    	global $wpdb;
    	$table_name = $wpdb->prefix . "simple_events";
    	if(!is_null($age) && !is_null($label)) {
    		$conditions = "WHERE event_label = '$label' AND $range ORDER BY event_start $limit ";
    	} elseif(!is_null($age)) {
    		$conditions = "WHERE $range ORDER BY event_start $limit";
    	} elseif(!is_null($label)) {
    		$currentTime = time();
    		$conditions = "WHERE event_label = '$label' AND event_end >= $currentTime ORDER BY event_start $limit ";
    	} else {
    		$currentTime = time();
    		$conditions = "WHERE event_end >= $currentTime ORDER BY event_start $limit ";
    	}

    In the four places after the $limit” part, add DESC. So the first instance would change from:

    $conditions = "WHERE event_label = '$label' AND $range ORDER BY event_start $limit ";

    to

    $conditions = "WHERE event_label = '$label' AND $range ORDER BY event_start $limit DESC";

    The 4 separate lines are for when there are limiters placed in the events tag (such as [events age=expired]. With this, I was able to just place it on the limiter for age. That made my upcoming events in ascending date order, and my past events (the ones that used the age limiter) in descending order.

    Hope that helps!

    http://wordpress.org/plugins/simple-events-calendar/

Viewing 1 replies (of 1 total)
  • duanemitchell
    Member

    @duanemitchell

    Very cool solution! Thanks!

    I seemed to have gotten this to work for my purpose by adding DESC to just the second instance:

    $conditions = "WHERE $range ORDER BY event_start $limit DESC";

    I have 3 event widgets in a sidebar with 3 different labels: Future, Current, and Past. The only category I want to sore in descending is the Past events. The above line seems to do it.

    Any comments on this or how the other lines affect sort?

Viewing 1 replies (of 1 total)
  • The topic ‘Changing event sort order’ is closed to new replies.