Created
October 29, 2014 03:22
-
-
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.
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 | |
//* 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