Hi Simon
I spent some time getting a basic version of this to work.
There are perhaps a number of ways you might go about it.
I have come up with some code that works with a particular workflow, if your requirements are different then you may want to modify it.
Firstly, the code, which should be added to your theme's functions.php file:
add_action( 'icl_copy_from_original', 'duplicate_child_posts' );
function duplicate_child_posts( $parent_id ) {
// All we have to go on is the original language parent post id
$parent_post_type = get_post_type( $parent_id );
$target_lang = apply_filters( 'wpml_current_language', NULL );
// get the translated parent post id
$translated_parent_id = apply_filters( 'wpml_object_id', $parent_id, $parent_post_type, false, $target_lang );
// get the child posts of the original parent post
$child_posts_args = array(
'post_type' => 'child-post',
'numberofposts' => -1,
'meta_query' => array(
array(
'key' => '_wpcf_belongs_' . $parent_post_type . '_id',
'value' => $parent_id
)
)
);
$child_posts = get_posts( $child_posts_args );
if ( !empty( $child_posts ) ) {
$create_post_helper = wpml_get_create_post_helper();
foreach ($child_posts as $child_post) {
$post_array = array(
'post_title' => $child_post->post_title,
'post_author' => $child_post->post_author,
'post_content' => $child_post->post_content,
'post_status' => $child_post->post_status,
'comment_status' => $child_post->comment_status,
'post_type' => $child_post->post_type
// add any standard post fields required that are missing
);
$child_id = $create_post_helper->insert_post( $post_array, $target_lang, true );
add_post_meta( $child_id, '_wpcf_belongs_' . $parent_post_type . '_id', $translated_parent_id );
}
}
}
Here's the expected workflow.
You have existing parent and child post content in one language.
You want to translate the parent post and have the translated parents have the same child posts as the original..
Note. Because of the way that post relationships are stored, child posts can only have one parent of a given post type. So you cannot have a child post be the child of two different language versions of a parent post. You must create child post copies for the additional languages so that, for example, an English child has an English parent, and the equivalent Spanish parent has a Spanish child (even if you don't actually translate the child and just copy across the English content).
So, you create a translation of your parent post.
You need to save this translation before copying across the content from the original so that the post id of this translation of the parent post is available to the code above.
Now hit the copy content button. That is what triggers the above code.
It will find the child posts of the original language version, and make copies of them in the new language (although the content is not actually translated), and it will assign the parent for these new child posts in the same language.
Try it with a few posts to see how it works and whether it suits your needs, but only after you take a backup of your existing site before making any changes.
Note that the translated child posts are not connected to the originals in any way, and only the standard WordPress fields and the post meta used to store the post relationship are copied, you may need to modify the code to copy additional standard or custom fields.
Let me know how you get on.