Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created November 19, 2013 01:03
Show Gist options
  • Save codearachnid/7538391 to your computer and use it in GitHub Desktop.
Save codearachnid/7538391 to your computer and use it in GitHub Desktop.
The Events Calendar: Fixed bug with improper column name when in admin main event list. Applies to TEC Pro 3.2. Notes: recently, while updating a client's website to the 3.2 plugin suite for Tribe's The Events Calendar I found that in the admin event list all the disappeared. After the normal, deactivating plugins, default theme etc I took the s…
<?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