Forked from jo-snips/tribe-admin-events-list.class.php
Created
February 22, 2016 17:46
-
-
Save jonahcoyote/d21be37d46b50aec36c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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