Skip Navigation

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

This thread is resolved. Here is a description of the problem and solution.

Problem:
Client was using code that uses both the Forms API and the WPML API to automatically duplicate posts submitted via a form into other languages (the content being copied from the original).

But these new posts were WPML "duplicates", meaning they were synched to the original and could not be independently edited.

Solution:
An updated version of the code which "un-synchs" the duplicate posts is offered below: https://toolset.com/forums/topic/edit-independently-in-front-end-ro-en-title-content-of-duplicated-posts/#post-1239002

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-606504

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 15 replies, has 2 voices.

Last updated by valentinP-3 5 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#1238092

I am trying to: Edit in front end independently the tile and content in two languages (RO/EN), of a post that has been published in front end and duplicated with a function you greatly provided.

I have two forms for adding posts and two for editing
I post let say in Romanian, and the post is duplicated to english. then go to english and translate the title but then when I go edit again the romanian version, it is overwritten on the english so the english edit do stay but is being replaced again with the romanian version.
Is there any way I can edit independently the title and content?
Here it should be mentioned that the other custom fields can be edited independently between the languages, but not the title and content

#1238120

Nigel
Supporter

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

Timezone: Europe/London (GMT+00:00)

Hi there

Is this the solution you are talking about for duplicating posts? https://toolset.com/forums/topic/auto-duplicate-frontend-submission-forms-posts-to-all-languages/

So your workflow would be something like publish a post with a Toolset Form in Romanian, which gets automatically duplicated to English (the post language is English, even though the content would actually be the original Romanian).

Viewing the "English" post on the front end you have a link to edit it with another Toolset Form. So you edit the post and change the title and content to English.

Now if you go back and look at the original Romanian post you find the title and content have been overwritten with the edits to the English post, is that an accurate description of the problem?

#1238121
Screen Shot 2019-05-01 at 13.33.43.png

Hi Nigel, your understanding is perfect, except the last "Now if you go back and look at the original Romanian post you find the title and content have been overwritten with the edits to the English post, is that an accurate description of the problem?".
After I adit the English, I can see it OK, I mean - the Romanian and English title and content are differently. But if after that I go to Romanian and make another edit, it overwritten the Romanian to English - so I loose the translation I have done it to English
Please help! I see that there is a button in the edit form English, where it says that it will Copy the Content from Romana - attached. I think if I can uncheck this option it may work

#1238131

Nigel
Supporter

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

Timezone: Europe/London (GMT+00:00)

Sorry, I don't recognise where that screenshot comes from.

That looks like a metabox from editing a post, but suggests its from a Form edit screen (where I don't see the same).

Could you clarify where that screenshot is taken?

#1238484
Screen Shot 2019-05-02 at 10.15.21.png

Yes, it is from the edit form , I attached a larger picture

#1238517

Nigel
Supporter

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

Timezone: Europe/London (GMT+00:00)

I don't recognise that at all, and I don't think you should be seeing it, because Forms are not (should not be) translatable.

Can I get your debug info? hidden link

#1238537

is it secured to send the debug info through this form? or you provide me with a hidden link, thx

#1238542

Nigel
Supporter

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

Timezone: Europe/London (GMT+00:00)

Sorry, did I not set that up, let me try again now.

#1238548

please let me know if you receved it, thx

#1238558

Nigel
Supporter

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

Timezone: Europe/London (GMT+00:00)

Thanks for that.

I can see that your plugins are not up-to-date.

After creating a backup, can you update to the current versions.

You won't (shouldn't) see the same translation options for your Forms because they are defined as not translatable.

Can you then confirm if you are still having the same initially reported issue with the current Toolset and WPML plugins. If so I'll set up a test to try and replicate.

#1238618

actually that translation options appear just after I translate the forms independently
I can not make the updates before Monday, as our IT person is in holliday
The problem s that my theme is not working well with the updated versions of Toolset and WPML, therefore I use these old versions
I am sure it is not from the updates, it sould be from other cause. Could you please replicate the setup and try see if it works on your setup? thanks a lot

#1238693

Nigel
Supporter

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

Timezone: Europe/London (GMT+00:00)

I'm just setting up a local site to test this, and the first thing I note is that the code to create duplicate posts does exactly that, makes duplicates.

In WPML "duplicates" are synched with the original post so that they have the same title and content and cannot be edited independently.

That's not a problem if you are working just in the backend, because if you try to edit a duplicate post you will be asked by WPML whether you want to disconnect the posts so that they can be edited separately.

You don't see such an option when editing with a Toolset Form on the front-end.

So first I'm looking for a solution to duplicate posts which are "copies" rather than "duplicates".

I'll post again with more news...

#1238695

Thanks, looking forward

#1239002

Nigel
Supporter

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

Timezone: Europe/London (GMT+00:00)

OK, I got a little help with the WPML API from a colleague and have updated the code you use to create the duplicates.

As I mentioned, the duplicates in WPML are synched so that the translations update with the same content as the original, and the solution is to "unsynch" them so that they are independently editable translations.

Here is the updated code:

/**
 * Automatically generate translation duplicates on posts created with a Toolset Form
 * and unsynch so that they are independently editable translations
 */
function quick_duplicate_save_data_action($post_id, $form_data)
{
    // Edit form ID(s)
    $forms = array(33);

    if (in_array($form_data['id'], $forms)) {
        global $sitepress;
        // make translated duplicates
        do_action('wpml_make_post_duplicates', $post_id);
        // get the IDs of all translations
        $trid = apply_filters( 'wpml_element_trid', NULL, $post_id, 'post_' . $form_data['post_type'] );
        $translations = apply_filters( 'wpml_get_element_translations', NULL, $trid, 'post_' . $form_data['post_type'] );
        // just the duplicate(s)
        foreach( $translations as $translation ){
            if ( $translation->element_id != $post_id ){
                // unlock synching of duplicate(s)
                delete_post_meta( $translation->element_id, '_icl_lang_duplicate_of' );
            }
        }
    }
}
add_action('cred_save_data', 'quick_duplicate_save_data_action', 10, 2);

For any existing posts you need to edit them in the back end and convert them from duplicates to just translations.

#1239183

It works perfectly!!! You are GREAT!
And I can still keep the other function (that I rename it) that duplicates other posts types that I need to be duplicated, and use this one to multiply / copy