I went to the archive of old support ticket, and I found this link (https://wpml.org/forums/topic/how-to-ensure-new-posts-have-duplicates-created-automatically/).
Basically, I added this code to the functions.php in addition to the other previous code mentioned above, and it seems to be working fine now.
I just wanted to double check with you to see that all these three codes used in combination, won't cause any further problem. I'd appreciate if you could look over!
add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
function my_duplicate_on_publish( $post_id ) {
global $post;
// 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 ($post->post_type=='your-post-type') {
//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' );
}
}
Hi, I would like to get an updated clone of your site if possible so I can run some additional tests and determine why the previous code stopped working. Please provide login credentials in the private reply fields here, or include a download link where I can download a Duplicator package.
Okay thanks, I don't see any obvious errors or cyclical function calls. I see that the new code actually does the post duplication part, and the code I originally provided was not set up to handle that. Looks okay to me, if it's working for you I think stick with it.