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

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

Assigned support staff: sarah.n.

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

Panagiotis

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

sarah.n
Supporter

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 pastebin.com 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.