Appending date to non-recurring events only

WordPress Event Management, Calendars & Registration Forums General Question Appending date to non-recurring events only

This topic contains 4 replies, has 2 voices, and was last updated by  Andy Burns 5 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #32045

    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
    #32051

    Add this to the first line of the function definition:

    if ( eo_recurs( $post_id ) ) {
       return;
    }
    
    Stephen Harris
    #32158

    Sorry, can you elaborate where?

    Andy Burns
    #32221

    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
    #32249

    Thank you Stephen, very helpful!

    Andy Burns
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.