Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jo-snips/7546719 to your computer and use it in GitHub Desktop.
Save jo-snips/7546719 to your computer and use it in GitHub Desktop.
<?php
/**
* update ~line 26 to include 2 argument params as such:
*/
add_filter( 'posts_orderby', array( __CLASS__, 'events_search_orderby' ), 10, 2 );
/**
* update static function `events_search_orderby` (replace with the following method starting at ~line 159)
*/
public static function events_search_orderby( $orderby_sql, $query ) {
if ( get_query_var('post_type') != TribeEvents::POSTTYPE ) {
return $orderby_sql;
}
global $wpdb;
$sort_column = ( $query->is_main_query() ) ? $wpdb->postmeta : 'eventStart';
$endDateSQL = " IFNULL(DATE_ADD(CAST($sort_column.meta_value AS DATETIME), INTERVAL eventDuration.meta_value SECOND), eventEnd.meta_value) ";
$order = get_query_var('order') ? get_query_var('order') : 'asc';
$orderby = get_query_var('orderby') ? get_query_var('orderby') : 'start-date';
if ($orderby == 'start-date') {
$orderby_sql = " {$sort_column}.meta_value {$order}, {$endDateSQL} {$order}";
} else if ($orderby == 'end-date') {
$orderby_sql = "{$endDateSQL} {$order}, {$sort_column}.meta_value {$order}";
}
return $orderby_sql;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment