Skip Navigation

[Resolved] How to automatically create translations of posts submitted with Forms

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 1 year, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2632979

Tell us what you are trying to do?
I want duplicates to be made in the second language (English) each time a user submits the form. The thing is that I've already done it a while ago, and I don't remember how I did it!!

Is there any documentation that you are following?
In the following tickets, I see the code, but nowhere I see where to put it (function file of the theme?)
https://toolset.com/forums/topic/edit-independently-in-front-end-ro-en-title-content-of-duplicated-posts/#post-1239002
https://toolset.com/forums/topic/auto-duplicate-frontend-submission-forms-posts-to-all-languages/

What is the link to your site?
hidden link
This is the form that actually duplicates in English the location posts when submitted
I'd like to do the same with other CPT, but I don't remember what I've done! hahah

#2633927

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset offers a place where you can add the custom code. You can add such custom code to "Custom Code" section offered by Toolset.

Please check the following doc:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

#2634003

Hi Minesh,

Thanks for the link, I will use it.

I finally found my code. It was in the child theme function file.

2 questions:
1) Best practices are to put in into the child theme file or the Toolset Custom Code tab? Or both are good?
2) Can I add multiple forms in the same code or I need one custom code by form? ($forms = array(20129, CPT1, CPT2, CTP3 ???);

Thanks!

// Automatically generate translation duplicates on posts created with a Toolset Form
function quick_duplicate_save_data_action($post_id, $form_data)
{
// Edit form ID(s)
$forms = array(20129);

if (in_array($form_data['id'], $forms)) {
global $sitepress;

// make translated duplicates
do_action('wpml_make_post_duplicates', $post_id);

}
}
add_action('cred_save_data', 'quick_duplicate_save_data_action', 10, 2);

#2634007

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

2 questions:
1) Best practices are to put in into the child theme file or the Toolset Custom Code tab? Or both are good?
==>
Both are good. But it depends on your choice. If you change the theme, you will have to move the code as well but Toolset "Custom Code" will offer you flexibility in that case.

2) Can I add multiple forms in the same code or I need one custom code by form? ($forms = array(20129, CPT1, CPT2, CTP3 ???);
==>
Yes, you can add more form IDs to that $forms array.

For example:

$forms = array(20129,9999,1111,2222,3333,4444);
#2635213

I finally added it to the Toolset settings.

I succeeded to add all the forms, so it's perfect.

Thanks! 🙂