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.

This topic contains 4 replies, has 2 voices.

Last updated by Riffaz 4 years, 9 months ago.

Assisted by: Riffaz.

Author Posts
August 8, 2020 at 4:16 pm #6761787

hansP-2

I am writing an import application and I would like to check if a specific term exists in a specific language. If it does not then create the term in that language.

questions:
- How to make sure get_term_by() searches inside the EN terms?
- How to make sure wp_insert_term() saves as an EN term?

// Switch to EN
global $sitepress;
$language_code = "en";
$original_lang = ICL_LANGUAGE_CODE;
$sitepress->switch_lang($language_code);

$term_name = 'sample';

// How to make sure it searches inside the EN terms?
$term = get_term_by('name', $term_name, 'product_cat');

if (! $term) {
    // How to make sure it is saved as an EN term?
    $result = wp_insert_term($term_name, 'product_cat');
}

// Switch back to original language
$sitepress->switch_lang($original_lang);
August 9, 2020 at 1:28 am #6762211

Riffaz

Hi,

Thank you for contacting WPML support.

This is a custom work. Anyhow, I am checking this with our developers and I will get back to you when I get the suggestions from them.

Regards,
Riffaz.

August 10, 2020 at 10:27 am #6768427

hansP-2

Hi,

Any news from the developers?

Regards

August 11, 2020 at 3:30 am #6773595

Riffaz

Hi,

They are trying reproduce the issue and checking this.
Sorry for the delay.
I will update you again once they find something (that will happen within this week)

Regards,

August 12, 2020 at 2:03 am #6781413

Riffaz

Hi,

Our developers informed me that your code work as expected.
Could you please explain what is the exact issue you are having with this? perhaps, adding some screenshots also will help in this.

Regards,