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
- - 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00
- - - - - - -

Supporter timezone: America/Lima (GMT-05:00)

Tagged: 

This topic contains 16 replies, has 2 voices.

Last updated by Andreas W. 2 days, 13 hours ago.

Assisted by: Andreas W..

Author Posts
February 7, 2025 at 11:14 am #16679232

lorenzP

Please stop sending my AI generated answers. This does not help at all. The answers are just wrong...

February 7, 2025 at 4:47 pm #16680669

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

We ran a quick test and could not confirm an issue in a minimal setup:
hidden link

Your code works as expected here without any workaround.

---

Now, I saw you reported this issue earlier, and we have a couple of open tickets on development about this issue, which are still not solved and this is why I tried to provide a possible workaround.

My previous answer truly was not AI-generated and I have today verified the provided workaround with one of our compatibility developers, who suggested a slight change:

// Use the wpml_current_language hook to get the current language
$current_language = apply_filters( 'wpml_current_language', NULL );

// Get the permalink for a specific post in default language (replace with your post ID)
$default_language = apply_filters( 'wpml_default_language', NULL );
do_action( 'wpml_switch_language', $default_language );
$post_permalink = get_permalink( $post_id );
  
// Get the post ID from the URL (this works for the default language, based on permalink)
$post_id_in_default_language = url_to_post_id( $post_permalink );
  
// Use WPML's filter to get the translated post ID in the current language
do_action( 'wpml_switch_language', $current_language );
$translated_post_id = apply_filters( 'wpml_object_id', $post_id_in_default_language );
  
// $translated_post_id now contains the post ID for the current language
echo $translated_post_id;

---

If it works on the production site and not on the staging then this would mean both sites are not identical. Revise installed theme and plugins and their versions. Make sure that staging and production use the same custom code.

If you would like me to take a look at the staging, let me know.

---

Also, I would like to invite you to, please log into the following test site and recreate the issue, so that we can take a closer look at your code and try to find a solution:

One-Click-Login:
hidden link