Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created October 29, 2014 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/440bf1c01ede03458b3d to your computer and use it in GitHub Desktop.
Save joshfeck/440bf1c01ede03458b3d to your computer and use it in GitHub Desktop.
Event Espresso 4's event category archives. Ordered by event datetime start and expired events removed.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
// re-order the event category archives
add_filter('posts_orderby', 'edit_event_category_archive_orderby' );
function edit_event_category_archive_orderby( $orderby ) {
global $wpdb;
if( is_tax( 'espresso_event_categories' )) {
$orderby = "{$wpdb->prefix}esp_datetime.DTT_EVT_start ASC";
return $orderby;
}
// not an event category, return default order by
return $orderby;
}
// add the datetime table to the event category archive join
add_filter( 'posts_join_paged', 'edit_event_category_archive_join_paged' );
function edit_event_category_archive_join_paged( $join_paged_statement ) {
global $wpdb;
if( is_tax( 'espresso_event_categories' )) {
$join_paged_statement .= "JOIN {$wpdb->prefix}esp_datetime
ON ( {$wpdb->prefix}esp_datetime.EVT_ID = {$wpdb->prefix}posts.ID ) ";
return $join_paged_statement;
}
// not an event category, return default join
return $join_paged_statement;
}
// remove expired events from the event category where
add_filter( 'posts_where', 'edit_event_category_archive_where_sql_no_expired' );
function edit_event_category_archive_where_sql_no_expired( $where ) {
global $wpdb;
if( is_tax( 'espresso_event_categories' )) {
$where .= " AND ( {$wpdb->prefix}esp_datetime.DTT_EVT_end > '" . date("Y-m-d H:s:i") . "' ) ";
return $where;
}
// not an event category, return default where
return $where;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment