Support » Plugin: Polylang » wp_insert_term with polylang

  • I’m trying to find the solution to this problem… I have a lot of terms that i need to input and it would take me about 5, 6 days just for that. I have 6 langs on the site and i’ve inputed the terms for default language programmaticly with wp_insert_term…
    I’m wondering can i input the term with this function for different language, how can i specify for which language i wan’t the term made with this function if i can at all….
    Does anybody know the solution to this problem

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Chouby


    Once you have the term_id, you can save the language with (assuming you want it to be in English):

    global $polylang;
    $polylang->model->set_term_language($term_id, 'en');

    Thanks for the advice but it didn’t work…
    Here is the code that i’m using
    $term = wp_insert_term(
    ‘aaaaas’, // the term
    ‘custom_tax’, // the taxonomy
    ‘description’=> ‘Just to see the language at its best’,
    ‘slug’ => ‘custom-tax’,
    global $polylang;
    $polylang->model->set_term_language($term->term_id, ‘en’);

    wp_insert_term returns the term_id so acording to you’r advice it should be enought but it isn’t

    Plugin Author Chouby


    wp_insert_term does not return *only* the term_id

    Thank you Chouby but i knew that it doesn’t return just term_id…
    Now i’m getting this error
    Call to a member function set_term_language() on a non-object in line…….
    It’s been painfull this for me…
    I have about 25000 terms that i need to enter and i can’t do it programatically
    Please advise.
    I did globalize $polylang

    As I had read into the module, I thought that the PLL_Model object was located at $term->model, not $polylang->model. Hope that may help.

    Plugin Author Chouby


    Sorry my previous answer was not exact enough but I meant that wp_insert_term does not return an object but an array. So you must use $term['term_id'] instead of $term->term_id as the first parameter in set_term_language.

    Call to a member function set_term_language() on a non-object

    Did you check for the availaibility of the $polylang object. If you use it in a plugin as soon as the plugin’s loaded then it is not available. As Polylang does respect the best practice to do nothing before the ‘plugins_loaded’ action has been fired.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_insert_term with polylang’ is closed to new replies.