We had this code to append the date to an event’s URL:
/*-----------------------------------------------------------------------------------*/
/* Including date in the slug of Event Organiser Events */
/*-----------------------------------------------------------------------------------*/
add_action( 'eventorganiser_save_event', 'my_include_date_in_event_slug', 15 );
function my_include_date_in_event_slug( $post_id ){
//Prevent infinite loops!
remove_action( 'eventorganiser_save_event', 'my_include_date_in_event_slug', 15 );
//Get event & schedule start date
$event = get_post( $post_id );
$date = eo_get_schedule_start( 'Y-m-d', $post_id );
//Form new slug and ensure it's unique
$new_slug = sanitize_title_with_dashes( $event->post_title .'-'.$date );
$new_slug = wp_unique_post_slug( $new_slug, $post_id, $event->post_status, $event->post_type, $event->post_parent );
//Update post
wp_update_post( array(
'ID' => $post_id,
'post_name' => $new_slug,
));
//Re-add the function
add_action( 'eventorganiser_save_event', 'my_include_date_in_event_slug', 15 );
}
However, it is not appropriate for recurring events. Can you advise on how to make this date appending conditional if it is not a recurring event?
Andy Burns
Add this to the first line of the function definition:
if ( eo_recurs( $post_id ) ) {
return;
}
Stephen Harris
Sorry, can you elaborate where?
Andy Burns
Like so:
add_action( 'eventorganiser_save_event', 'my_include_date_in_event_slug', 15 );
function my_include_date_in_event_slug( $post_id ){
if ( eo_recurs( $post_id ) ) {
return;
}
//Prevent infinite loops!
remove_action( 'eventorganiser_save_event', 'my_include_date_in_event_slug', 15 );
...
}
Stephen Harris
Thank you Stephen, very helpful!
Andy Burns