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 Andreas W. 6 months ago.

Assigned support staff: Andreas W..

Author Posts
April 24, 2019 at 6:47 pm #3676101

hussamS

i have a website and i give the chance for the client to post thier property from the front end.. now i need to automatically create a duplicate for that property to the other language
both languages are english and Arabic

April 24, 2019 at 9:44 pm #3677239

Andreas W.
Supporter

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

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for contacting the WPML Support.

WPML does not offer a feature to automatically duplicate submitted content, anyhow I would like to invite you to provide a feature request here:
https://wpml.org/suggest-a-new-feature-for-wpml/

The fastest way to achieve this task would be using our Translation Management Plugin.
https://wpml.org/documentation/translating-your-contents/

Go to WPML -> Translation Management, select the content filter "Properties", simply mark all the new properties in the list. You will see the translation status for each property on the right side. Then select the duplicate option at the bottom of the page.

Let me know if you do have any further question.

Kind regards
Andreas

April 25, 2019 at 7:20 am #3679463

hussamS

Hi Andreas,

I found this code was posted by one of your team... it is some how working but seems need some modification to be Suitable to my case as i need it for properties only

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

/**
* Duplicate a post/page/custom post on publish or update
*
**/
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;
}
// don't save for revisions
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
return $post_id;
}
// Check permissions
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) ) {
return $post_id;
}
} else {
if ( !current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
}

$master_post_id = $post_id;
$master_post = get_post($master_post_id);
$language_details_original = $sitepress->get_element_language_details($master_post_id, 'post_' . $master_post->post_type);

// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'wpml_duplicate_on_publish');

foreach($sitepress->get_active_languages() as $lang => $details){
if($lang != $language_details_original->language_code){
$iclTranslationManagement->make_duplicate($master_post_id, $lang);
}
}

// re-hook this function
add_action('save_post', 'wpml_duplicate_on_publish');
}

April 25, 2019 at 2:59 pm #3683677

Andreas W.
Supporter

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

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for your message. You are correct. This function might serve for the task. We will need to take a look at your site and access to FTP for further assistance.

I would like to request temporary access (wp-admin and FTP) to your site to take a better look at the issue. It would be better to a testing site where the issue is replicated.

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.

Maybe I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok with you.

IMPORTANT

Please make a backup of site files and database before providing us access.
If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this:
hidden link

Kind regards
Andreas

April 25, 2019 at 5:12 pm #3684623

Andreas W.
Supporter

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

Timezone: America/Lima (GMT-05:00)

Hello,

The following WPML Hooks will be the one that you need to apply:

https://wpml.org/wpml-hook/wpml_make_post_duplicates/

Please take note that our support policy does not cover any custom code solutions. If you need any assistance you might consider contacting a contractor here:
https://wpml.org/contractors/

https://wpml.org/purchase/support-policy/

Kind regards
Andreas

April 25, 2019 at 5:22 pm #3684643

hussamS

Hi Dear,
I have check the link you have sent to me.. but i just want to confirm is it going to work for " property" posts only?

April 25, 2019 at 5:32 pm #3684749

Andreas W.
Supporter

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

Timezone: America/Lima (GMT-05:00)

Hello,

The documentation mentions that the $master_post_id is supposed to be the ID of the post to duplicate from. It can be that ID of a post, page or custom post. The “master post” doesn’t need to be in the default language.

The hook example shows how to create duplicates for a post when we insert it from the front-end.

For more assistance I will need to ask you to reach out to a contractor. Maybe you also could ask the theme authors for assistance as this custom post type is based on the theme options.

Kind regards
Andreas