Skip Navigation

[Resolved] Split: Posts created/updated in 2nd language only visible in 2nd language – update post form with wpml with translations

This support ticket is created 4 years, 3 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.

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

Last updated by simonM-5 4 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1448575

Hi Minesh

Coming back to you on the updates: From your reply #1437959

What about updates to forms which have already been submitted, what would be the expected behavior in this case? Does an update count as a submission? In which case, would an update cause further triplicates to be created?
==>
Update form code should be written and tested so that if duplicates are already available, it should not makes more duplicate. You should open a new ticket and share all the required information like where you added the post edit form with access details and assign it to me.

For updates our requirements would be:

1) If duplicates already exist:
a) Updates to taxonomies: Taxonomies should be updated across all duplicates. Their translations should happen then via Taxonomies Translation.
b) Updates to numeric fields: the updated value should be replaced in the duplicates with the updated value.
c) Updates to the big freeform text custom fields (wpcf-we-are-looking-for, wpcf-nanny-what-i-can-offer). This text should remain untranslated and be copied to existing duplicates, replacing the existing content.

Kind regards
Simon

#1455891

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

1) If duplicates already exist:
===>
The duplicate posts will be created automatically using the code we added that means duplicate posts will always exist as soon as you create a post first time in any language.

a) Updates to taxonomies: Taxonomies should be updated across all duplicates. Their translations should happen then via Taxonomies Translation.
b) Updates to numeric fields: the updated value should be replaced in the duplicates with the updated value.
c) Updates to the big freeform text custom fields (wpcf-we-are-looking-for, wpcf-nanny-what-i-can-offer). This text should remain untranslated and be copied to existing duplicates, replacing the existing content.
==>
So, you are saying if I make any modifications to any Native Nanny Post using Toolset edit form those modifications should also be recorded on all other duplicate posts. Having said that, If I modify something on Spanish post all those modifications should be copy to other languages. correct?

#1455895

HI Minesh

Yes, the user should be able to edit the form in ANY language and that change should be pushed to all duplicates as specified, regardless if the language is the primary language (EN) or secondary language (DE, ES):

a) Updates to taxonomies: should be updated across all duplicates.
b) Updates to numeric fields: the updated value should be replaced in the duplicates with the updated value.
c) Updates to the big freeform text custom fields (wpcf-we-are-looking-for, wpcf-nanny-what-i-can-offer). This text should remain untranslated and be copied to existing duplicates, replacing the existing content.

So independent of the language in which the users makes the change, all versions of the post should be updated accordingly.

I hope the requirements are clear now.

This should be true for both CPTs Native Nanny Ads and Family Ads.

Best regards
Simon

#1455899

Minesh
Supporter

Languages: English (English )

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

Ok great. Can you please send me the URL of the page where I can see the Edit form you added for both CPTs Native Nanny Ads and Family Ads.

Please specify if I need to use the different login to edit the both CPTs Native Nanny Ads and Family Ads posts.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1457595

Hello,

Minesh is on holiday, you will get answer tomorrow.

#1460027

Minesh
Supporter

Languages: English (English )

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

Ok - so the thing is that there is no automatic sync feature available.

The things become again contrary (against WPML setup), where for instance you set the setting for WPML for the custom field to "copy" that means it will copy the values and now with forms, you edited the post in X language and the updates/changes you made to edit form's custom fields, you want to copy those changes to other addon languages.

However, I can guide you with the filters and hooks you may like to try yourself:
- To get translated taxonomy term ID, you should use the WPML hook: wpml_object_id
=> https://wpml.org/wpml-hook/wpml_object_id/

You need to use the cred_save_data action hook where you should add all required custom code:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

I would suggest trying the above the hook and the required code to sync the edits you made on edit form to other language posts.

However, I also would like to know that the edit form will be only available on the English language - is that correct?
=> hidden link

#1460229

Hi Minesh

Thanks for your update.

I am aware that there is no auto-sync available, however you said in a previous update that you would be able to make updates to Posts propogate to all language versions of the Post.

Can you please help me to understand if you see the problem with WPML not being able to translate the various elements, or whether it is difficult for you to propogate updates resulting from editing Forms to the posts' translations?

According to the WPML homepage:
"With WPML you can translate pages, posts, custom types, taxonomy, menus and even the theme’s texts." and "Every theme or plugin that uses WordPress API runs multilingual with WPML"
==> On our site we are wanting to translate custom fields, posts and taxononmies, so I believe WMPL should be able to do that.

Can you please be more specific about what you mean with the following sentence?

"The things become again contrary (against WPML setup)"
==> what "things" do you mean here exactly? And contrary to what?
==> what have we done that is non-standard, other than automatically duplicate the Posts? I was given the impression that the posts HAD TO BE duplicated in order to be able to display all Posts in all 3 languages.

Thanks for the links, however I am not a PHP developer, therefore I can only review the links provided and assess whether I can implement that or not.

To answer your question at the end of your post: the edit form of course has to be available in every language - a German or Spanish speaker cannot be expected to use an Edit Form in English or vice versa.

Kind regards
Simon

#1468811

Minesh
Supporter

Languages: English (English )

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

So, finally, I've added the following code to "Custom Code" section offered by Toolset to snippet "edit-native-nanny-ads"

function func_wpml_sync_posts_in_all_languages( $post_id, $form_data ){
$forms = array( 923 );
if ( in_array($form_data['id'],$forms) ){
    global $sitepress;
  
     $current_language= apply_filters( 'wpml_current_language', NULL );
         $active_langs = $sitepress->get_active_languages();
         unset($active_langs[$current_language]);
        
        $type = 'native-nanny-ad';
        $translated_object_ids = array();
        foreach ( $active_langs as $key=>$val):
            $translated_object_ids[$key] = apply_filters( 'wpml_object_id', $post_id, $type, false, $key );        
      
        foreach((array)$_POST['type-of-work'] as $x=>$y):
              $trans_types_of_work[$key][]  = apply_filters( 'wpml_object_id', $y, 'type-of-work', false, $key );
      	   endforeach;
          
           
        endforeach;
 
          foreach($translated_object_ids as $k=>$id):
              wp_set_object_terms( $id , $trans_types_of_work[$k], 'type-of-work' );
          endforeach;

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

The code I wrote for the taxonomy 'type-of-work', can you please confirm when you change the taxonomy 'type-of-work' it also has take effect on other languages. If yes, you need to add such code for your other taxonomies.

#1473545

Hi Minesh

Thank you very much for the code, I have a few questions regarding it, as I'm not a PHP developer, but have a fair idea what the code is doing, I just need confirmation:

1) The code is showing an error on Line 24 under Toolset > Settings > Custom Code - can it be that there is a missing endforeach? It looks like you opened one on line 21, and didn't close it. Is that correct?

2) In array() I just put the post ID of the relevant Edit Form, so I would create a new one for edit family ads.

3) At $type, I just instances of the native-nanny-ad slug with the family-ad slug for the other type of ads

4) $trans_types_of_work: this is a name which you have created, correct? So I would replace this with another made up name like eg $trans_native_languages for the Native Languages taxonomy

And in general:
5) Is it possible to add all the taxonomies into this one snippet? If so, which parts do I need to repeat and adjust? I'm guessing lines 24-33 and lines 59-68. Or do I need to repeat all the code?

6) What then, about the other two types of fields (numeric and the big free text field) on the CPT Native Nanny Ad. The updated numeric value and the text in the big message field would need to get propagated to all language versions. Does your code do this too or will that need to be handled separately?

7) The snippet you posted in your last post is shorter than what is in the code snippet, is that intentional?

Thanks and regards
Simon

#1474941

Minesh
Supporter

Languages: English (English )

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

1) The code is showing an error on Line 24 under Toolset > Settings > Custom Code - can it be that there is a missing endforeach? It looks like you opened one on line 21, and didn't close it. Is that correct?
==>
There was a little Typo in the code. I've corrected it.

2) In array() I just put the post ID of the relevant Edit Form, so I would create a new one for edit family ads.
==>
Yes - you should create a new code snippet like "edit-family-ads" and replace the edit form ID of the edit family ad form.

3) At $type, I just instances of the native-nanny-ad slug with the family-ad slug for the other type of ads
==>
Yes , you should change that with your new snippet "edit-family-ads" and change the slug accordingly.

4) $trans_types_of_work: this is a name that you have created, correct? So I would replace this with another made up name like eg $trans_native_languages for the Native Languages taxonomy
==>
You can create any variable. It really requires PHP programming knowledge. I suggest you should check with Pro Devs.

5) Is it possible to add all the taxonomies into this one snippet? If so, which parts do I need to repeat and adjust? I'm guessing lines 24-33 and lines 59-68. Or do I need to repeat all the code?
==>
Yes, Again, as I said, it requires PHP programming knowledge.

6) What then, about the other two types of fields (numeric and the big free text field) on the CPT Native Nanny Ad. The updated numeric value and the text in the big message field would need to get propagated to all language versions. Does your code do this too or will that need to be handled separately?
==>
Yes, you need to add that code on your own.

7) The snippet you posted in your last post is shorter than what is in the code snippet, is that intentional?
==>
Yes, I removed the non-used code.

#1476727

Hi Minesh

Thanks for that.

OK, I did the following tests:

1) Created 3 new Nanny Ads, one in EN, one in DE, and one in ES.
>>> 2 duplicates were created for each one, regardless of language created in ✅

2) Edited each one in its language of creation, changing the title and taxonomy for which you wrote the code (type-of-work).
>>> All duplicates are reflecting the update in all languages ✅

3) Tried to update the Nanny Ad created in ES using EN
>>> The updates are only seen in EN and are not being replicated to the other duplicates. 😕
Original name (created in ES): Nanny anuncio creado en ES 20200124 1215
Updated name (updated in ES): Nanny anuncio creado en ES 20200124 1215 Change in ES FT > occasional
Updated name2 (updated in EN): Nanny anuncio creado en ES 20200124 1215 Change in ES FT > occasional > FT (in EN)

The taxonomy is only changed on the EN version, the DE and ES versions retain the old title and old taxonomy settings, so the language duplicates have become out of sync.

Kind regards
Simon

#1476741

Minesh
Supporter

Languages: English (English )

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

Can you please share direct links of the edit post form link and steps I need to follow.

I have set the next reply to private which means only you and I have access to it.

#1480747

Minesh
Supporter

Languages: English (English )

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

I would like to double-check with you if anyone is working on the site? If Yes, as I suggested in my last reply, you should create staging site and share the access details with me.

#1480751

HI Minesh

This is our development site. We currently are using only the dev site, and yes, I am working in it at the moment too. I took a backup 2h ago.

Your colleague Christian Cox managed to copy our site in a previous support ticket, presuming with Duplicator or similar.

You are welcome to do the same, you already have access to our WP admin. Let me know if you need more info.

Kind regards
Simon

#1484467

Minesh
Supporter

Languages: English (English )

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

Ok - so finally, I'm able to create a new duplicator copy from your server and I successfully installed the duplicator on my local test server.

Now, as #1 and #2 are working just fine. Lets talk about #3.

3) Tried to update the Nanny Ad created in ES using EN
>>> The updates are only seen in EN and are not being replicated to the other duplicates. 😕
==>
You are talking about when you update the post from the frontend Edit form - correct? If yes: where you added the edit form to edit the entry in ES?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.