Support

Home Forums Event Espresso Premium Redirect expired event to specific URL

Redirect expired event to specific URL

Posted: November 3, 2020 at 4:43 pm

Viewing 1 reply thread


tschoerie

November 3, 2020 at 4:43 pm

Hi,

Found the following script which works well for me when adding it to my child themes functions.php. Could you please tell me how to redirect expired events to a specific URL instead of home_url:

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 );

Thanks,
Steve


Tony

  • Support Staff

November 4, 2020 at 4:19 am

Hi there,

You set the URL to be using within window.location.replace("");

So, do you mean a specific external URL for all? For example:

window.location.replace("https://google.com");

Or an internal page:

window.location.replace("<?php echo esc_url(echo home_url() . '/some-page/'"); ?>");

Or something specifically set on the event itself?

Viewing 1 reply thread

The support post ‘Redirect expired event to specific URL’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso