Change permalinks with ACF values

I was thinking too ‘difficult’. Instead of rebuilding a new permalink structure I could have easily updated the new permalink the way I want to have it.

So I deleted the entire rewrite part and changed the query in acf/save_post to the following:

if ( ! empty( $_POST[ 'acf' ][ $ad_title ] ) ) {

    $entered_title = $_POST[ 'acf' ][ $ad_title ];
    $cleaned_title = preg_replace( '/[^A-Za-z0-9\-\s]/', '', 
    $entered_title ); // Removes special chars.
    $post_name     = sanitize_title( $cleaned_title );
    $city_name     = get_field( 'sd_city_search_value', $post_id );
    $new_slug      = strtolower( $city_name ) . '-' . $post_name . '-' . $post_id;

    // update acf field
    update_field( 'sd_ad_title', $cleaned_title, $post_id );

    // update post status + post title (if needed)
    global $wpdb;
    $wpdb->update(
        $wpdb->posts,
        array(
            'post_title'  => $cleaned_title,
            'post_name'   => strtolower( get_field( 'sd_city_search_value', $post_id ) ) . '-' . $post_name . '-' . $post_id
        ),
        array(
            'ID' => $post_id
        )
    );

    clean_post_cache( $post_id );

}