Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Apina/5966404 to your computer and use it in GitHub Desktop.
Save Apina/5966404 to your computer and use it in GitHub Desktop.
custom espresso_display_table function that makes it possible to order by time instead of ordering by date only. Replaces the function of the same name in the espresso_table.php template
/*
Shortcode Name: Espresso Table
Author: Seth Shoultes
Contact: [email protected]
Website: http://www.eventespresso.com
Description: Only show events in a CATEGORY within a certain number number of days into the future and a qty. The example below only shows events in a certain category that start within 30 days from the current date.
Usage Example: [ESPRESSO_TABLE max_days="30" qty="3" category_identifier="gracecard" order_by="state"]
Custom CSS for the table display
Notes: This file should be stored in your "/wp-content/uploads/espresso/templates/" folder and you should have the custom_includes.php files installed in your "/wp-content/uploads/espresso/" directory.
*/
function espresso_display_table($atts){
global $wpdb;
$org_options = get_option('events_organization_settings');
$event_page_id =$org_options['event_page_id'];
global $load_espresso_scripts;
$load_espresso_scripts = true;//This tells the plugin to load the required scripts
extract(shortcode_atts(array('event_category_id'=>'NULL','category_identifier' => 'NULL','show_expired' => 'false', 'show_secondary'=>'false','show_deleted'=>'false','show_recurrence'=>'true', 'limit' => '0', 'order_by' => 'NULL', 'max_days'=>''),$atts));
if ($category_identifier != 'NULL'){
$type = 'category';
}
$show_expired = $show_expired == 'false' ? " AND e.start_date >= '".date ( 'Y-m-d' )."' " : '';
$show_secondary = $show_secondary == 'false' ? " AND e.event_status != 'S' " : '';
$show_deleted = $show_deleted == 'false' ? " AND e.event_status != 'D' " : '';
$show_recurrence = $show_recurrence == 'false' ? " AND e.recurrence_id = '0' " : '';
$limit = $limit > 0 ? " LIMIT 0," . $limit . " " : '';
$days = " WHERE ADDDATE('".date ( 'Y-m-d' )."', INTERVAL ".$max_days." DAY) >= e.start_date AND e.start_date >= '".date( 'Y-m-d' )."' ";
$order_by = $order_by != 'NULL'? " ORDER BY ". $order_by ." ASC " : " ORDER BY date(start_date), ese.start_time, id ASC ";
if ($type == 'category'){
$sql = "SELECT DISTINCT e.* FROM " . EVENTS_CATEGORY_TABLE . " c ";
$sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.cat_id = c.id ";
$sql .= " JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id = r.event_id ";
$sql .= " JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
if ( $max_days != "" ) {
$sql .= $days;
$sql .= " AND c.category_identifier = '" . $category_identifier . "' ";
} else {
$sql .= " WHERE c.category_identifier = '" . $category_identifier . "' ";
}
$sql .= " AND e.is_active = 'Y' ";
}else{
$sql = "SELECT e.*, ese.start_time, ese.end_time FROM " . EVENTS_DETAIL_TABLE . " e ";
$sql .= "LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
if ( $max_days != "" ) {
$sql .= $days;
$sql .= " AND e.is_active = 'Y' ";
} else {
$sql .= " WHERE e.is_active = 'Y' ";
}
}
$sql .= $show_expired;
$sql .= $show_secondary;
$sql .= $show_deleted;
$sql .= $show_recurrence;
$sql .= $order_by;
$sql .= $limit;
echo espresso_get_table($sql);
}
// the espresso_get_table function goes here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment