Hi,
I'm hooking into the wp_after_insert_post action to save some post data in a custom database table.
The problem is that when completing the first translation (first translation meaning that you "complete" the translation for the first time) with the Advanced Translation Editor, the custom fields (created with ACF -- setup as "copy") apparently are not yet saved into the postmeta table.
Welcome to WPML support. I'd be happy to help you with this.
Can you provide me with a test staging site where I can check this? To debug this issue further, I would need to check your site settings once, for this I would need temporary access (wp-admin and ftp) to your site.
So could you please provide me with those details, you will find the needed fields for this below the comment area when you log in to leave your next reply. hidden link
Note:
Backup your sites before providing the credentials or if possible provide credentials for the test site
Provide the link where the code is added
Provide me permission to disable/enable everything on the test site.
Hi Shekhar,
the save_post is triggered before the wp_after_insert, so I think that if there are no meta available in insert, they will not be available in save.
What happens to the do_action( 'wpml_sync_all_custom_fields', $id) if I pass the ID of the original post in the main language?
It Synchronizes the values of all custom fields across all translations of a given post. It only does it if the translation option for these custom fields is set to Copy.
I have created a test site here: hidden link can you create a simple example page with demo data and add the function so we can debug this further, No need to add the full code, you can just vardump the results to show the issue.
I've added the code in functions.php:658 of the 2021 theme.
Just create a new post, fill the custom field created with acf (not required though), publish, translate once, you'll see that no meta is printed in the errorlog upon saving the translation the first time.
Just beware that it will save when you publish the post in the original language 🙂