Please make sure to update to WPML 4.3.6 and check our list of Known Issues before reporting

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 6 replies, has 2 voices.

Last updated by berryP-2 1 year, 11 months ago.

Assigned support staff: Yuri.

Author Posts
March 4, 2018 at 11:40 pm #1535645


I have a site with a custom post type.
This post type is set to "appear as translated".
I use an ACF front-end form to create posts. That all works like a charm.

BUT when a user goes to a translated page which has the form on it, then the (source) language of the post the user created is default in the language of the page. Now I don't want to translate my posts or have them in non-default languages. I want them all in one language.

How can I change the source language of a post, through a function (not by hand), after it has been saved.

I searched the forums, found a topic (can't find it anymore) but that didn't work.

I also raised the question on ACF forum but no reply has come yet.
See hidden link

March 5, 2018 at 9:21 am #1535899


Hi, currently we have a hook that can change the language of an element so it might be what you need for this. It's called "wpml_set_element_language_details" and the documentation for it is located here:

Let me know if this is what you were looking for.

March 5, 2018 at 9:23 am #1535900


Thanks for the reply, but the given code example didn't do the trick. The other topic also spoke of this action, but as I said, the given example didn't work.

March 5, 2018 at 1:34 pm #1536325


Hi, how are you executing the creation of the post? Is it via custom code, plugin, theme functionality? Do you have any documentation available for the method you are using? Can additional hooks be added/triggered from within this code?

March 5, 2018 at 3:29 pm #1536512


Please read my first message, it is explained in there.

March 5, 2018 at 7:06 pm #1536808


This is my function:

function sd_change_language( $post_id ) {

    if ( 'cpt' == get_post_type( $post_id ) ) {
        $wpml_element_type           = apply_filters( 'wpml_element_type', 'cpt' );
        $get_language_args           = array( 'element_id' => $post_id, 'element_type' => 'cpt' );
        $original_post_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args );
        $set_language_args           = array(
            'element_id'           => $post_id,
            'element_type'         => $wpml_element_type,
            'trid'                 => $original_post_language_info->trid,
            'language_code'        => 'en',
            'source_language_code' => null

        do_action( 'wpml_set_element_language_details', $set_language_args );
add_action( 'acf/save_post', 'sd_change_language', 1, 1 );
March 6, 2018 at 12:58 am #1537020


I found conflicting code. It works now.