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.

Author Posts
March 6, 2019 at 10:57 am #3278271


Hi there!

I got 1000 of imported custom posts en English, posts will use same images as original.

I wold like to copy custom fields form english translation to other languages programmaticaly.

1. Get list of English Posts ID
2. For each post will find this custom fields which is contain ids or images associated with English post in database
3.Duplicate founded custom fields for another languages i have (es,ru,fr).

Is this possible as it is, or shold i know about something because of new Multimedia Translation etс?

Or may be there is some filter or action of WPML what i need to run?

Thank you!

March 7, 2019 at 9:14 am #3283047

Konrad Karpieszuk

Languages: English (English )

Timezone: Europe/Rome (GMT+02:00)


I suggest you one of two approaches. Choose which one is better for you:

prop 1: adjust id during duplication of custom fields
- go to wpml > media and translate every image (you can duplicate them)
- in your custom code for duplicating custom field, before you save id of the image, adjust it using our filter: to get id of translated version of the image

prop 2: adjust id during display of the image
- don't duplicate the images, keep them only in original language
- in your theme, in the place which will display the image wrap it in the code which does:
-- switch temporary language context to original one. for this:
--- save temporary current language to variable with this filter:
--- get default language code
--- switch to default language with this action (use language code from previous point)
-- display image from custom field
-- switch back to temporary stored (in first point) current language, again with

I hope I helped 🙂

March 7, 2019 at 4:04 pm #3285652


Amazing! Konrad! Very complete answer! Thank you A LOT! I will always ask you if will need)

My issue is resolved now. Instead long writing and asking unnecessary stuff, like access or debug information... You gave me TWO solutions! Thank you so much!

March 8, 2019 at 8:04 am #3289892

Konrad Karpieszuk

Languages: English (English )

Timezone: Europe/Rome (GMT+02:00)

haha, this is nice comment, thank you and I am happy I've helped 🙂