WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_create/wp_insert_category Undefined Error (5 posts)

  1. WebTechGlobal
    Member
    Posted 5 years ago #

    Hey all,

    Greatly appreciate help with this one I just don't get it.

    wp_create_category or wp_insert_category on my CSV 2 POST plugin works sometimes but not others! I'm currently using it on http://www.1book2books.co.uk and it created 3 category automatically.

    250 hits later it's now telling me...

    Fatal error: Call to undefined function: wp_insert_category()

    I don't get this at all I can't even begin to guess why it happens. It's not the first time either and when it happened 2 weeks ago I forgot about it because it went away. So there must be something with WordPress that loads taxonomy sometimes but not others.

    My plugin action is in the footer if that helps.

    Thanks and there is £2.50 paypal in it for someone who provides a true fix.

    Ryan

  2. jikoyster
    Member
    Posted 4 years ago #

    I had the same problem and find the answer at taxonomy.php in wp-includes directory.

    use wp_insert_term instead
    here's the code:

    if(!is_term($term, $taxonomy)){
      wp_insert_term($term, $taxonomy, $args);
    }

    where $term is the category name
    and $taxonomy is either 'tag' or 'category'
    $args is an array fields for the category same with wp_insert_category

  3. kiranthomman
    Member
    Posted 4 years ago #

    Thanks jikoyster I too had a problem with wp_insert_category inside functions it seemed to work for some calls but refused to work during others. Finally I tried what you said and it works like a charm

  4. zsiswick
    Member
    Posted 4 years ago #

    Yeah, I was totally beating my head against the wall until I found this post. Thank you jikoyster!

  5. ChefGaby
    Member
    Posted 4 years ago #

    When you use wp_insert_category you would add "category_description" and "category_parent" to the array. For this function the values are "description" and "parent".

    Here is a complete example of the usage:

    $arg = array('description' => "my description", 'parent' => "cat_ID");
    $new_cat_id = wp_insert_term("cat name", "category", $arg);

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.