This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by Mathieu 2 months ago.

Author Posts
August 16, 2019 at 1:55 pm #4406727

Mathieu

Hi,

i'm using both latest WPML, ACF and Advanced Custom Fields Multilingual (1.4.0).

I have 3 custom post type, related to each other, using the ACF relationship field :

Artist (can have multiple series and artworks)
Series (can have multiple artworks and one artist)
Artworks (can have one artist and one serie)

The base language of the website is English.

I'm DUPLICATING all the post to French, using the function provided by WPML :

add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
function my_duplicate_on_publish( $post_id ) {
if (( 'artists' == get_post_type( $post ))
or ( 'artworks' == get_post_type( $post ))
or ( 'series' == get_post_type( $post ))

) {
$post = get_post( $post_id );

// don't save for autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// dont save for revisions
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
return $post_id;
}

// we need this to avoid recursion see add_action at the end
remove_action( 'wp_insert_post', 'my_duplicate_on_publish' );

// make duplicates if the post being saved
// #1. itself is not a duplicate of another or
// #2. does not already have translations

$is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );

if ( !$is_translated ) {
do_action( 'wpml_admin_make_post_duplicates', $post_id );
}

// must hook again - see remove_action further up
add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
}
}

Here is an example of my problem:

When i add a new ARTWORK...the artwork post gets created in English, then duplicated in French. That works fine.

BUT, the ARTIST post related to the ARTWORK, gets updated in English, but the French version do not get updated. Same goes for the SERIE post.

Is there a way to easily get the related post to update their translated version?

On another note, i'm doing all this to be able to have translated slugs in my URL...so if you know a better way tell me! I read on the forums and the only way to get translated slugs in the URL seems to be by duplicating/translating the post.

Thanks!

August 17, 2019 at 2:43 pm #4410209

Mathieu

OK, for those who wants to achieve this, i found a solution :

You'll need to use ACF post 2 Post (https://wordpress.org/plugins/post-2-post-for-acf/)

ACFP2P have a hook that is called after each related post is updated, all you need to do is to use the WPML hook "wpml_admin_make_post_duplicates" on each posts :

add_action('acf/post2post/relationship_updated', 'my_post_updated_action');
function my_post_updated_action($post_id) {
// $post_id == the post ID that was updated
// do something after the related post is updated

do_action( 'wpml_admin_make_post_duplicates', $post_id );
}