Skip Navigation

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

Problem:

If I use get_post_meta WordPress function to get the ACF Clone field, the result is the original language ID on a translated page which is wrong. For example:

var_dump(get_post_meta(get_the_ID(), 'cloned_gallery', true));

Solution:

The customer found out that using wpml_object_id WPML hook in combination with get_post_meta is the workaround:

$images = get_post_meta(get_the_ID(), 'cloned_gallery', true);
 
foreach ($images as $key => $image) {
    $translatedImages[] = apply_filters( 'wpml_object_id', $image, 'attachment', true, null); 
}
var_dump($translatedImages);

Relevant Documentation:

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

https://www.advancedcustomfields.com/resources/clone/

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.

Our next available supporter will start replying to tickets in about 4.73 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by Angeloca 11 months, 1 week ago.

Assisted by: Christopher Amirian.

Author Posts
May 21, 2023 at 10:51 am #13684315

Angeloca

Advanced Custom Fields Translated ID.

May 21, 2023 at 11:27 am #13684403

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

I created a WordPress, WPML, ACF Pro and Multilingual installation that you can access here:

hidden link

Please replicate the issue about the copied gallery items with prefix option and add your code to theme's functions.php file or somewhere else (inform us) to see ethe result and the inconsistency.

Thanks.

May 24, 2023 at 10:30 am #13706233

Angeloca

Hi Christopher,
here you go

Main lang hidden link
Secondary lang hidden link

In each page there are two var_dump(): the first is from a normal gallery (ids are translated), the second is from a cloned + prefix gallery (ids are not translated)

May 24, 2023 at 3:08 pm #13709031

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

I am going to report this to the second-tier support for further investigation.

Just to be on the same page, as already get_field function retrieves the correct ID for the Clone Gallery, there is a way to achieve this and it will get a lower priority for the get_post_meta method.

I will inform you as soon as I have an update.

Thanks.

May 24, 2023 at 3:11 pm #13709097

Angeloca

Hi Christopher,
yes I know, as I said in the chat, I wanted to point out the behaviour incosistency ๐Ÿ™‚

Also, for anybody reading the ticket with the same issue, I've ended up using `wpml_object_id`filter on the non-translated ids ๐Ÿ™‚

May 25, 2023 at 6:54 am #13712411

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thank you for the clarification. Just to make sure if I can check the workaround you used.

Here is the issue with the Cloned field:

var_dump(get_post_meta(get_the_ID(), 'cloned_gallery', true));

It retrieves the original language ID instead of the translated one.

But I tried to use wpml_object_id and then add the result instead of get_the_ID() in the code but it returned Bool False.

Did the workaround you use work on the Cloned gallery? And if yes can you give the hint?

Thank you.

May 25, 2023 at 1:13 pm #13716509

Angeloca

Hi Christopher,
here it is ๐Ÿ™‚

$images = get_post_meta(get_the_ID(), 'cloned_gallery', true);

foreach ($images as $key => $image) {
    $translatedImages[] = apply_filters( 'wpml_object_id', $image, 'attachment', true, null); 
}

var_dump($translatedImages);

May 26, 2023 at 6:02 am #13719849

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Thank you. Please kindly set this ticket as resolved so that I can create a summary of your workaround and add it to the ticket.

Thanks.

May 26, 2023 at 6:32 am #13719889

Angeloca

Thank you ๐Ÿ™‚

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.