WordPress WPML permalink error in admin

I trying to be clear,

I have a custom post type who have a custom taxonomy

Read More
Event > Zone

I build taxonomy with this slug (need to translate “zone”):

'rewrite'  => array( 'slug' => '%events%' ),

I build CPT with this slug (need to translate “events” too):

'slug' => '%event%/%zone%',

I also two functions for rewriting url :

For “events”:

add_filter( 'post_type_link' , 'events_permalink_structure', 10, 4 );

function events_permalink_structure( $post_link, $post )
{
    $status = $post->post_status;
    $type = $post->post_type;

  if( $status == "publish" && ( $type == "events" ) )
  {

    if ( false !== strpos( $post_link, '%zone%' ) ) {

        $event_type_term = get_the_terms( $post->ID, 'zone' );

        if( is_array( $event_type_term ) ){

          $post_link = str_replace( '%zone%', array_pop( $event_type_term )->slug, $post_link );

          $translated_slug = apply_filters( 'wpml_translate_single_string', 'events', 'WordPress', 'URL slug: events' );

          $post_link = str_replace( '%event%', $translated_slug, $post_link );

        }

    }

  }
    return $post_link;
}

and for taxonomy :

add_filter('term_link', 'term_link_filter', 10, 3);

function term_link_filter( $url, $term, $taxonomy ) {

    if ( false !== strpos( $url, '%events%' ) ) {

        $event_type_term = get_the_terms( $term->term_id, 'zone' );

        $translated_slug = apply_filters( 'wpml_translate_single_string', 'events', 'WordPress', 'URL slug: events' );

        $url = str_replace( '%events%', $translated_slug, $url );

    }

    return $url;

}

Almost everything is perfect. Every Url are generated and works.
My problem is when I’m in admin, I can’t save a post without wrong url.

My language admin is EN and I have 4 languages.
When I’m create a new post, if admin is FR and Language is EN I have and url like this :

/evenements/asian-pacific/cdcsdcds/ (evenements = FR, asian-pacific = EN)

if admin is EN and Language is EN I have and url like this :

/events/asian-pacific/bbdfgb/ (Everything is ok)

if admin is FR and Language is FR I have and url like this :

/fr/events/asie-pacifique/sdcdscdsc/ ‎(events could be evenements in FR)

I’m lost, could you help me please?

Thanks,
David

Related posts