Created
October 12, 2018 18:54
-
-
Save joshfeck/7d419c1f12a0ec1c8b6153931521e89e to your computer and use it in GitHub Desktop.
exclude events from event lists (front-end) that don't have tickets available right now
This file contains hidden or 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 | |
| function de_ee_tweak_event_list_exclude_ticket_expired_events_where( $SQL, WP_Query $wp_query ) { | |
| if ( isset( $wp_query->query_vars['post_type'] ) | |
| && | |
| ( $wp_query->query_vars['post_type'] == 'espresso_events' || ( is_array( $wp_query->query_vars['post_type'] ) | |
| && | |
| in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) | |
| && ! $wp_query->is_singular ) { | |
| $SQL .= ' AND Ticket.TKT_end_date > "' . current_time( 'mysql', true ) . '"'; | |
| $SQL .= ' AND Ticket.TKT_start_date < "' . current_time( 'mysql', true ) . '"'; | |
| $SQL .= ' AND Ticket.TKT_deleted=0'; | |
| } | |
| return $SQL; | |
| } | |
| add_filter( 'posts_where', 'de_ee_tweak_event_list_exclude_ticket_expired_events_where', 15, 2 ); | |
| function de_ee_tweak_event_list_exclude_ticket_expired_events_join( $SQL, $wp_query ) { | |
| if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events' || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) { | |
| if ( ! $wp_query->is_espresso_event_archive && ! $wp_query->is_espresso_event_taxonomy ) { | |
| $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() . '.ID = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name() . ' ) '; | |
| } | |
| $SQL .= ' INNER JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' AS Datetime_Ticket ON ( Datetime_Ticket.DTT_ID=' . EEM_Datetime::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() . ' ) INNER JOIN ' . EEM_Ticket::instance()->table() . ' AS Ticket ON ( Datetime_Ticket.TKT_ID=Ticket.' . EEM_Ticket::instance()->primary_key_name() . ' ) '; | |
| } | |
| return $SQL; | |
| } | |
| add_filter( 'posts_join', 'de_ee_tweak_event_list_exclude_ticket_expired_events_join', 3, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment