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 7 replies, has 3 voices.

Last updated by sarah.n 4 years, 10 months ago.

Assigned support staff: sarah.n.

Author Posts
November 3, 2014 at 1:15 pm #504510

Jasper

Hi,

I am trying to automatically create the translations for other languages when creating a new post. For example, when I create a new page I'd like WPML to automatically create the translations in the other languages (as duplicates). I don't really care how they are created, it's important to me that they are created and available to manipulate programatically. In other words, I'd like to have a specific post ID for _every_ language after creating a new post.

If I remember correctly, this is or used to be an option? If it's not an option, is it easy to implement through a filter of some kind?

Thanks in advance!

November 3, 2014 at 5:03 pm #504786

Beda
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Italian (Italiano )

Hello Jasper

If the "duplicate content" in WPML > Translation Management is not what you are looking for, maybe this thread could provide you the needed solution:

http://wpml.org/forums/topic/auto-duplicate-postspages-on-publish/

Look for the latest suggestion provided by Sarah.n

Please let me know if this helped you.

Thank you

November 4, 2014 at 8:38 am #505072

Jasper

Hi Beda,

I tried Sarah's code from the other topic, but it didn't work. I got some notices in the debug output:

Notice: Trying to get property of non-object on line:
if($lang != $language_details_original->language_code){

I get this same notice a total of 12 times.

November 4, 2014 at 4:00 pm #505510

Beda
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Italian (Italiano )

Hello Jasper

As I can see, this did not work.
Please remove then the added code, if you did not already do so.

I must involve the 2nd Tier support into this, please could you provide me access to your WP Admin and FTP, in case we need to look closer at your installation.

==> Please also confirm to have a full backup of your website and database at your disposal.

Could you please also provide me the debug information?
http://wpml.org/faq/provide-debug-information-faster-support/

I will forward your ticket as soon as I have the needed details.

Thank you

November 5, 2014 at 4:33 pm #506341

Beda
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Italian (Italiano )

Hello Jasper

Sarah, from the 2nd Tier support, will contact you very soon and try to solve the issue in the best possible manner.
I have contacted her and she informed me that the code snippet provided in the other thread is outdated.
She will have to look into your specific installation and then create a new solution.

Please would it be possible for you to provide us access to your installation?
We would need access to the WP Admin Interface and the FTP Account.
You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

==>Please confirm a full backup of your website and database in your next answer.

Would it also be possible to provide the debug information?
http://wpml.org/faq/provide-debug-information-faster-support/

Thank you for your patience.

November 6, 2014 at 9:08 am #506678

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Hello Jasper,

This is Sarah here. You wrote:

For example, when I create a new page I'd like WPML to automatically create the translations in the other languages (as duplicates).

It would be nice if you could clarify for me whether you create posts/pages via code or from within the WordPress admin.

Until I hear from you I will assume that you are creating posts/pages via code using wp_insert_post() so I will go ahead based on this to test some code locally.

November 7, 2014 at 10:02 am #507498

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Hello Jasper,

I have some code for you here. I tested it and it appears to work fine with me. It would be nice to get your feedback when you can on whether it works for you too.

add_action( 'save_post', 'wpml_duplicate_on_publish');
function wpml_duplicate_on_publish( $post_id ) {
	global $sitepress, $iclTranslationManagement;
	// 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;
	}

	
	// we need this to avoid recursion see add_action at the end
	remove_action('save_post', 'wpml_duplicate_on_publish');
		
		// make duplicates if the post being saved does not have any already or is not a duplicate of another
		$has_duplicates = $iclTranslationManagement->get_duplicates( $post_id );
		$is_duplicate = get_post_meta($post_id, '_icl_lang_duplicate_of', true);
		if ( !$is_duplicate &&  !$has_duplicates) {
			icl_makes_duplicates( $post_id );
		}
	// must hook again - see remove_action further up
	add_action('save_post', 'wpml_duplicate_on_publish');
}
November 7, 2014 at 10:14 am #507507

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

I saw your private comment Jasper. Thanks.
Let us know if you need anything else from us 🙂

The topic ‘[Closed] How to automatically create (duplicate) translations?’ is closed to new replies.