Background of the issue:
I'm creating a plugin that uses the save_post hook. In this code, I'm trying to retrieve the language_code from the saved post using the following:
This code worked perfectly on the staging site at hidden link but when I moved the code into production, it is not working consistently. I created a log file for the plugin.
Symptoms:
When the post with ID 31559 is saved, it returned the following from wpml_post_language_details hook:
However, when saving a post with the ID 17085, I get the following:
Array
(
[language_code] => en
[locale] => en_US
[text_direction] =>
[display_name] => English
[native_name] => English
[different_language] =>
)
I've no idea why it works for some but not others and like I said it works perfectly on the staging site.
Questions:
Why is the wpml_post_language_details hook returning empty values for some posts but not others?
Why does the code work perfectly on the staging site but not on the production site?
It might be that something went wrong during the migration process from development to production.
When you edit a post with such a problem, do you see a language associated with it?
If not, then associate it with a language.
You can also try the troubleshooting section.
1. Take a backup of the DB of your site.
2. Go to WPML -> Support -> Troubleshooting (link)
3. Once on the troubleshooting screen, press the following buttons and check if it helps. Press each button at a time and wait for the process to complete.
- 'Disable cache for language switcher templates'
- 'Clear language information and repopulate languages' button (if it is showing)
- 'Synchronize posts taxonomies' for the relevant post type
- 'Clear the cache in WPML'
- 'Remove ghost entries from the translation tables'
- 'Fix element_type collation'
- 'Fix WPML tables collation'
- 'Synchronize local job ids with ATE jobs'
- 'Synchronize translators and translation managers with ATE'
- 'Assign translation status to duplicated content'
- 'Set language information'
- 'Reset languages' Press this button only if you didn't add a custom language!
- 'Fix terms count'
- 'Fix post type assignment for translations'
- 'Cleanup and optimize string tables'
- 'Clear invalid strings'
*** Please backup your database before using this.***
Regards,
Itamar.
The topic ‘[Closed] The wpml_post_language_details hook is not working consistently’ is closed to new replies.