WPML Translating a term/taxonomy programmatically

I have all terms in English and I am creating/duplicating the same ones for German language by using foreach on english terms and this way i create all terms for German language.

The problem is when i need to assign an German term to its English version.

I tried the trick with TRID like this:

$trid = $sitepress->get_element_trid($englist_term_id, "taxonomy_name");

$sitepress->set_element_language_details($new_term_id, "taxonomy_name", $trid, $lang_code, $sitepress->get_default_language());

The problem is that $trid does not take any value (The first line of the above code)

Probably there is some other way to accomplish this!

2 Answers
2

Ok I found the solution.

Actually taxonomy name on icl_translation table is stored with prefix called “tax_” which means taxonomy. The above code would work like this:

$trid = $sitepress->get_element_trid($englist_term_id, "tax_taxonomy_name");

$sitepress->set_element_language_details($new_term_id, "tax_taxonomy_name", $trid, $lang_code, $sitepress->get_default_language());

The difference is tax_ prefix.

Cheers!

Leave a Comment