Hi,
I have a site where users can submit “small notes” from a frontpage form created in ACF.
I would like these “notes” to be duplicated into the other languages I have on the site, but nomather what I do, the only things duplicated are standard WP-fields (title, author etc). None of my ACF are included in the automatic duplication-process! 🙁
The code I use to duplicate:
add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
function my_duplicate_on_publishh( $post_id ) {
$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;
}
if ( isset( $post->post_type ) && $post->post_type == 'custom-post' ) {
// 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_make_post_duplicates', $post_id );
}
}
// must hook again - see remove_action further up
add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
}