Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created April 30, 2018 17:02
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/02b6d1156f83ac27b7f489edf4580125 to your computer and use it in GitHub Desktop.
Save joshfeck/02b6d1156f83ac27b7f489edf4580125 to your computer and use it in GitHub Desktop.
Adds a JavaScript redirect to the home page when the event is expired. Event Espresso 4
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function ee_add_redirect_expired_events() {
if ('espresso_events' == get_post_type() && is_single() ){
$id = get_the_id();
$event = EEH_Event_View::get_event( $id );
if( $event instanceof EE_Event ) {
$where_params_for_event = array(array('EVT_ID' => $event->ID()));
if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) == 0 &&
EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0
) {
?>
<script>
window.location.replace("<?php echo esc_url(home_url()); ?>");
</script>
<?php
}
}
}
}
add_action( 'wp_print_footer_scripts', 'ee_add_redirect_expired_events', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment