WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
wp_insert_term with polylang (7 posts)

  1. danncoba
    Member
    Posted 3 months ago #

    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

    http://wordpress.org/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 3 months ago #

    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');
  3. danncoba
    Member
    Posted 3 months ago #

    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
    array(
    '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

  4. Chouby
    Member
    Plugin Author

    Posted 3 months ago #

    wp_insert_term does not return *only* the term_id
    http://codex.wordpress.org/Function_Reference/wp_insert_term#Return_Values

  5. danncoba
    Member
    Posted 3 months ago #

    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

  6. jjchinquist
    Member
    Posted 3 months ago #

    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.

  7. Chouby
    Member
    Plugin Author

    Posted 3 months ago #

    @danncoba
    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.

Reply

You must log in to post.

About this Plugin

About this Topic