Hi,
i’m using both latest WPML, ACF, ACF Post-2-Post 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?
We started coding actions with the acf/save_post but it starting to look like a real spaghetti, and i’m sure there probably an easier way o achieve this.
Thanks for your help!
OK, for those who wants to achieve this, i found a solution which is so far working without a problem :
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, thus updating your duplicated post data:
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 );
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.