Home › Toolset Professional Support › [Resolved] WPML language duplicate not being created correctly 100% of the time
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 23 replies, has 2 voices.
Last updated by Minesh 11 months ago.
Assisted by: Minesh.
Hi Support
We have noticed that sporadically in production that the translated version of a post (post type "nanny") is not being duplicated correctly when the user is submitting the form "Post Form - Place a Nanny Ad - Unverified Nanny". This should be executed due to the provided Custom Code snippet: func-sync-language-duplicates-on-submission
Example of Nanny that worked correctly:
original post ID = 58824 (en_gb), language dupe is 58827 (de_de)
Example of Nanny which didn't get duplicated correctly:
original post ID = 58434 (de_de), language dupe is 58844 (en_gb)
I pressed the Plus button to add the translation manually. The translated post ID is 58844 (en_gb).
The translated post 58844 doesn't get the all values populated correctly in wp_postmeta. Doing a very quick query on the database (Adminer installed temporarily for you to verify):
select *
from wp_postmeta
where post_id in (58844, 58827)
I see 42 meta_key/meta_value records for the post which worked correctly, and only 3 for the manually translated one.
We have a few more examples from when this happened in the past. Like I said it is infrequent, but I would like to understand how to fix it and whether we can "repair" the manually translated posts to match their automatically translated counterparts.
Particularly worrying is that the manually translated posts don't get the meta_key
'_icl_lang_duplicate_of'
In that case will updates to the original posts be propagated correctly to their language duplicates?
Kind regards
Simon
Hello. Thank you for contacting the Toolset support.
Can you please share exact steps I will have to follow from start to end when I try to create new job post and what steps I will have to follow to translate that newly added job post later.
Please share all required details with links where required with frontend user access details.
I have set the next reply to private which means only you and I have access to it.
If it works 99% times as expected then its really hard for us to know the actual culprit and to find where the issue could possibly resides. Debugging such way is not at all recommended is its really time consuming and at last 99% of times we will not be able to reproduce the issue. Rather then debugging it will be considered as R & D and that does not recommended.
I suggest you keep the patient and keep really close eye when you create a new job ad and when you able to reproduce the issue you should strait file a ticket and share all the necessary steps that we should follow that should help us to reproduce the issue. I hope that makes sense.
HI Minesh
There is still the issue of the "broken" duplicate records with all the missing postmeta data.
I was thinking, instead of pressing the + button to generate the translation when it happens, wouldn't it be possible to "imitate" the duplication process by duplicating and modifying the code snippet func-sync-language-duplicates-on-submission, so that I could use it manually in the future by popping in the post IDs of posts which didn't get duplicated properly?
Then I would delete those faulty language duplicates, pop in their original language post IDs and run the code manually. That way all the correct post_meta should be created. Should work right?
I made a first stab at rewriting the code. Could you please verify that it is correct?
function sync_language_duplicates_on_submission( $post_id, $post_data ){ $posts = array( xxx, xxx, xxx ); if ( in_array($post_data['id'],$posts) ){ global $sitepress; // Use WPML API do_action( 'wpml_make_post_duplicates', $post_id ) ; } } add_action( 'cred_save_data', 'sync_language_duplicates_on_submission', 12, 2 );
Thanks and kind regards
Simon
The code you shared looks ok.
I would like to know - are you using manual translation to translate your post or automatic translation editor (ATE)?
I was thinking, instead of pressing the + button to generate the translation when it happens, wouldn't it be possible to "imitate" the duplication process by duplicating and modifying the code snippet func-sync-language-duplicates-on-submission, so that I could use it manually in the future by popping in the post IDs of posts which didn't get duplicated properly?
===>
I do not have any hook to offer that runs when you try to translate the post. I hope you set your desired and correct translation preference for your custom fields taxonomies etc..etc..:
- https://wpml.org/documentation/getting-started-guide/translating-custom-fields/#indicating-which-custom-fields-to-translate
If you want to just copy the content from your original language post then you should try to follow the steps given with the following link:
- https://wpml.org/documentation/translating-your-contents/displaying-untranslated-content-on-pages-in-secondary-languages/#how-to-copy-content
Here is the official API doc for the hook that might help you:
- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-606504
More info:
- https://wpml.org/documentation/translating-your-contents/using-different-translation-editors-for-different-pages/
Hi Minesh
We use the Classic (manual) translator.
I believe we have set up all the translation options correctly. Like I said, it works 99% of the time.
I tried
- creating the above code snippet in our dev environment,
- deactivated the existing func-sync-language-duplicates-on-submission temporarily,
- created a new Job Ad from the front end
- ran the new custom code snippet func-sync-language-duplicates-individual-posts with the Job Ad ID 27463.
Unfortunately I didn't get a new language duplicate as expected. Could you please take a look?
I think I need a new private message to give you dev credentials again, since the other ticket is now closed.
Thanks and regards
Simon
Can you please tell me what is exactly not working when you create new job ad?
I have set the next reply to private which means only you and I have access to it.
Before going further I see the code snippet you added that is "func-sync-language-duplicates-on-submission" is inactive.
Can you please activate the code snippet you added from "Custom Code" section offered by Toolset and then try to create a job ad and check if it successfully duplicated or not.
HI Minesh
func-sync-language-duplicates-on-submission is our normal code which runs automatically in the background to create the duplicates, when users create posts on the front end.
For some reason, in 1% of the cases it's not working (on production site), so I'm trying to create a new code that I can run/use manually for the those failing posts, which simply takes the input of the post id which didn't get duplicated correctly, and performs the same job as the code func-sync-language-duplicates-on-submission
I deliberately deactivated it, so that a duplicate would NOT be created automatically, for testing purposes. So that I can test the new snippet to see if the created duplicate has all the correct postmeta.
I hope you can understand now what I mean.
Thanks and kind regards
Simon
ok.
Can you please tell me what is the new code snippet name and where you added that?
HI Minesh
CURRENT CODE (working 99% of the time): (temporarily deactivated on dev for testing purposes)
func-sync-language-duplicates-on-submission
NEW CODE (for manually translating one post, with hopefully the same postmeta being produced as the original code):
func-sync-language-duplicates-individual-posts
Both are custom code snippets in dev.native-nanny.de > Toolset > Settings > Custom Code
Kind regards
Simon
NEW CODE (for manually translating one post, with hopefully the same postmeta being produced as the original code):
func-sync-language-duplicates-individual-posts
====>
With the new code I've adjusted the code as given under:
function sync_language_duplicates_individual_posts( $post_id, $post_data ){ // Post Form - New Job Ad (929) $form_ids = array( 929 ); /// add form id if ( in_array($post_data['id'],$form_ids) ){ global $sitepress; // Use WPML API do_action( 'wpml_make_post_duplicates', $post_id ) ; } } add_action( 'cred_save_data', 'sync_language_duplicates_individual_posts', 12, 2 );
You will have to use form ID in comparison. Now when you try to add new job Ad:
- hidden link
It should duplicate the post in another language. As you can see I've adjusted the form ID with the above code.
- Post Form - New Job Ad (929)
Please note that tthe above hook will only run when you create new post using the form ID 929 that is Post Form - New Job Ad (929).
While creating a new post if you still want to duplicate the specific post then you should try to create a new job Ad using the same form and use the following code:
function sync_language_duplicates_individual_posts( $post_id, $post_data ){ // Post Form - New Job Ad (929) $form_ids = array( 929 ); /// add form id if ( in_array($post_data['id'],$form_ids) ){ global $sitepress; // Use WPML API do_action( 'wpml_make_post_duplicates', $post_id ) ; $another_post_id = 27463; do_action( 'wpml_make_post_duplicates', $another_post_id ) ; } } add_action( 'cred_save_data', 'sync_language_duplicates_individual_posts', 12, 2 );
Also - I see you want to make duplicate for the following post (rather using above hook)
- hidden link
If you doing it manually - please make sure to translate above post using "WordPress Editor" instead of "WPML Translation Editor. Please check the following screenshot: hidden link
Hi Minesh
I think you are misunderstanding 100% what is happening and what we need. I will try to explain again.
Existing custom code snippet func-sync-language-duplicates-on-submission works perfectly well almost 100% of the time, but the very odd time it doesn't work, just for post type nanny. We are not having any problems with post type family, job-ad or nanny-ad. When any of these are created, we always get a correct language duplicate post.
I want a way (via the new code) to perform the SAME language duplicate creation process, but for just those post IDs which failed to get duplicated correctly. So it should be a custom code snippet which remains inactive but which I can just run manually in those odd edge cases when the post is not duplicated correctly, simply by inserting the failed post id in the array. In other words, kind of doing the same job as func-sync-language-duplicates-on-submission RETROACTIVELY.
At no point do we ever want to be creating individual posts which have to be translated manually. The new custom code should act as a "repair" for the those posts which didn't get correctly handled in the first place by our existing code snippet func-sync-language-duplicates-on-submission. The posts must be duplicated (correctly) in such a way, that if the user UPDATES their original post, that their changes are also propagated correctly to the language duplicate post.
I hope I was able to explain more clearly what we need.
Thanks and kind regards
Simon