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 1 reply, has 2 voices.

Last updated by sarah.n 6 years, 11 months ago.

Assigned support staff: sarah.n.

Author Posts
July 19, 2013 at 8:51 am #146547


I am creating a theme, that will be reusable for some sites, and some of my plugins require some specific terms on a taxonomy to work. (Prepopulated data)

Because I want to have little interference on the setup (except on updating plugins) is there a way to check if the taxonomy terms exist and if not add them via the WPML API into each translation?

I tried to do this for a term called "featured". In my plugin I require the following:

featured for default language
featured-{ICL_LANGUAGE_CODE (active)} for each of the languages installed via wpml.

I tried to insert the "featured" programmatically using the normal wordpress process, but it didn't show on the default language taxonomy list menu. So I am guessing there is an extra efford here with the WPML API?

July 19, 2013 at 9:56 am #146584


Languages: English (English ) German (Deutsch )

Hello Panagiotis,

Here are some tips that will hopefully point you to the right direction:

When you insert your terms using wp_insert_term() WPML will at the same time create a record of the newly inserted term in icl_translations table.

What you need to do is set the language and associate terms (original to translation/s)

This is done by

1. Grabbing the trid value of the original with this function:

// get the trid from the original
 $trid = $sitepress->get_element_trid($original_term_term_taxonomy_id, $element_type);

2. Then updating the translated term record to associate it to the original with this function:

// associate the translated term to the original           
$sitepress->set_element_language_details($translated_term_taxonomy_id, $element_type, $trid, $language_code, $sitepress->get_default_language());

Before calling any of the above functions, don't forget to add a

global $sitepress;

If you need further help in implementing the above code in your function feel free to provide the code you are using currently. We probably simply need to add to it a few lines to play well with WPML so if I could see what you have so far it will be easier.

If you find it more practical you can also provide the entire file over or over email (let me know and I'll email you)

The topic ‘[Closed] Add a taxonomy to three languages programmatically’ is closed to new replies.