Please make sure to update to WPML 4.3.4 before reporting any issue

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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.

This topic contains 7 replies, has 2 voices.

Last updated by Jamal 5 months, 2 weeks ago.

Assigned support staff: Jamal.

Author Posts
June 7, 2019 at 4:05 pm #3977585



I use
do_action( 'wpml_set_element_language_details', $args );

to translate post and taxonomy programmatically (only by code)

Now, I need for "translated post" to add the media (featured and gallery) of the original post.

Should i use the same wpml_set_element_language_details or it's something different ?


June 7, 2019 at 4:41 pm #3977757


Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)


Thank you for contacting WPML Support. I will be glad to help with this.

Media files are still a custom post type, which means that wpml_set_element_language_details is enough to translate them.

But the featured image and the gallery are usually stored as custom post types, which may need more processing. Can you provide more details on your use case?

Best regards,
WPML Support

June 7, 2019 at 4:54 pm #3978077


Thanks for your quick answer.
As you said, it's right. I just checked the tables on my db and the images are post_type "attachment" with parent_id the original post.

So basically I have to deal with wpml_set_element_language_details for each attachment post_type ?
I need to use element_type "post_attachment" ?

Is there a code example of this ? to be sure i use the good elements.


June 7, 2019 at 4:58 pm #3978085


Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)


Yes, you will need to perform the action for each attachment.
Yes, you will need to use element_type "post_attachment".

For a code example, see the action documentation page
The code example is not specific for attachments, but you can adapt it to your use case.

Best regards,

June 8, 2019 at 10:56 am #3980905


Ok, So I think made it with the images, seems working.
But I got problem with the taxonomy.

I'm setting the term value of original post with this ligne :

wp_set_post_terms($original_post_id, $rooms_EN, 'additional_features', FALSE);

Then I run this line to add the translation :


It use a function I made bellow, but it doesn't work, I don't get the "original tax id" the current value is NULL :

function wpml_insert_tax_fr($original_post_id,$tax_name,$translated_post_id,$content) {
$original_tax = get_the_terms( $original_post_id, $tax_name );
$original_tax_id = "";
foreach ($original_tax as $term) { $original_tax_id = $term->term_id; }
$original_tax_trid = apply_filters( 'wpml_element_trid', NULL, $original_tax_id, 'tax_'.$tax_name );
$new_term = wp_set_post_terms($translated_post_id, $content, $tax_name, FALSE);
$set_language_args_FR = array(
'element_id' => $new_term['term_id'],
'element_type' => 'tax_'.$tax_name,
'trid' => $original_tax_trid,
'language_code' => 'fr',
'source_language_code' => 'en'

do_action( 'wpml_set_element_language_details', $set_language_args_FR );

June 8, 2019 at 8:36 pm #3981341


ok, found the problem. Because wp_set_post_terms return an array with numeral key.

I got a new problem now.
When I set a post terms with same value for each lang, all terms are in one lang but not both.
If I want to set the value "1" for both lang, i will see all of them in one lang.

how can i fix that ?
there is not so much doc and example

June 9, 2019 at 11:45 am #3983033


Ok I think i found it.
I set different slug but same name by updating the term...

June 10, 2019 at 8:13 am #3985781


Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)


My apologies for the late reply, I was not working the weekend. However, for support rules, we are able to handle only one issue at the time. This helps us to bring you a better service and also help other users to find all the information here exposed.
For that reason, I have to kindly ask you to open a new thread if you need further assistance.

Best regards,