Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 - -
16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 - -

Supporter timezone: Asia/Jerusalem (GMT+02:00)

This topic contains 1 reply, has 2 voices.

Last updated by Itamar 5 months, 2 weeks ago.

Assisted by: Itamar.

Author Posts
September 13, 2024 at 9:05 pm #16177792

johnM-108

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:

$post_language_details = apply_filters( 'wpml_post_language_details', NULL, $post_id ) ;
$post_language = ( is_array( $post_language_details ) ? $post_language_details['language_code'] : false );

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:

Array
(
    [language_code] => 
    [locale] => 
    [text_direction] => 
    [display_name] => 
    [native_name] => 
    [different_language] => 1
)

You can see almost all the values are empty.

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?

September 15, 2024 at 7:47 pm #16180763

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

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.