Multisite Content Copier and WPML translations

Multisite Content Copier

I’m using the Multisite Content Copier in a multi-site network with WPML.
In all sites, main language pages and post IDs remain the same.

I’m using Multisite Content Copier to copy all translated post and pages to the main site, and get rid of the network.

When I copy a custom post type in a translated language from one site to another the post appears in the destination site as a post in the main language (english).

I expected to get the translated post associated with it’s translation in english (the main language).

Of course, previously I’ve created the translated language in the destination site.

I can solve it by manually associate each post and page with it’s translation, but that’s a lot of time.

Is there anyway to get it done automatically?

  • Ash
    • WordPress Hacker

    Hello @vueloiv

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    This is not possible out of the box, I am afraid. But, I am marking this as a feature request.

    But if you need it urgently, please note that it will need a fair amount of custom code. You can post a job in our job board where you can hire a developer to assist further: https://premium.wpmudev.org/wpmu-jobs/ Please note that, no WPMU official staff is available in the job board.

    Cheers
    Ash

  • Ryan
    • WPMU DEV Initiate

    I think I found a solution for this. Add this to your functions.php file:

    function f5_sort_wpml_lang($posts_created, $source_blog_id, $args) {    
    
        foreach($posts_created as $orig_post => $new_post) {
    
            switch_to_blog( $source_blog_id );
    	        $original_post_details = apply_filters( 'wpml_post_language_details', null, $orig_post );
    	        $post_type = get_post_type($orig_post);
    	        $get_language_args = array('element_id' => $orig_post, 'element_type' => $post_type );
    	        $original_post_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args );
    	        	$id_of_original_trans = apply_filters( 'wpml_object_id', $orig_post, $post_type);
    	restore_current_blog();
    
            //$partner_id = $posts_created[$id_of_original_trans];
            $partner_language_args = array('element_id' => $orig_post, 'element_type' => $post_type );
            $partner_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args );
    
            $set_language_args = array(
                'element_id'    => $new_post,
                'element_type'  => 'post_'.$post_type,
                'trid'   => $partner_language_info->trid,
                'language_code'   => $original_post_language_info->language_code,
                'source_language_code' => $original_post_language_info->source_language_code
            );
    
            do_action( 'wpml_set_element_language_details', $set_language_args );
    
        }
    
    }
    add_action('mcc_copy_posts', 'f5_sort_wpml_lang', 10, 3);

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.