Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client needs PHP filters or functions with WPML to retrieve the ID of translated media attached to a Meta Box field group on their homepage.
Solution:
We recommend using the

wpml_object_id

hook to obtain the ID of a translated media. Here is an example of how to use this hook to get the German translation ID for an attachment:

echo apply_filters( 'wpml_object_id', 25, 'attachment', FALSE, 'de' );

If the translation is missing, it will return NULL. For more details, please refer to our documentation:
WPML Object ID Hook
How to Get Other Languages of Current Post

If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket at WPML Support Forum.

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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Bigul 4 months, 1 week ago.

Assisted by: Bigul.

Author Posts
July 5, 2024 at 9:42 am #15897640

adrienR-5

Background of the issue:
I have a Meta Box field group attached to my homepage, inside it I have a Meta Box advanced field with max number of image 1. I would like in my other translated homepage to display the translation of this image that is tied to the homepage FR.

Symptoms:
I need PHP filters or functions with WPML to get the ID of my translated media.

Questions:
Is there any PHP filter or function in WPML to get the ID of a translated media?

July 5, 2024 at 10:42 am #15898024

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

You can use the wpml_object_id hook for this purpose. It will return the post/term id in the current language or a specified language. Like the following.

// will return the German attachment ID for attachment ID 25. If the translation is missing it will return NULL
echo apply_filters( 'wpml_object_id', 25, 'attachment', FALSE, 'de' );

Please refer to the following docs for more details and let us know your feedback.

https://wpml.org/wpml-hook/wpml_object_id/

https://wpml.org/faq/how-to-get-other-languages-of-current-post/

--
Thanks!

Bigul

July 5, 2024 at 11:23 am #15898218

adrienR-5

Hello Bigul,

Thanks so much, that is what I was looking for!