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.

Our next available supporter will start replying to tickets in about 7.04 hours from now. Thank you for your understanding.

This topic contains 6 replies, has 2 voices.

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

Assigned support staff: Yuri.

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

berryP-2

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

Yuri

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: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-689675

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

March 5, 2018 at 9:23 am #1535900

berryP-2

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

Yuri

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

berryP-2

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

March 5, 2018 at 7:06 pm #1536808

berryP-2

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

berryP-2

I found conflicting code. It works now.