WordPress.org

Support

Support » Plugins and Hacks » [Resolved] wp_create/wp_insert_category Undefined Error

[Resolved] wp_create/wp_insert_category Undefined Error

  • 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

Viewing 4 replies - 1 through 4 (of 4 total)
  • jikoyster

    @jikoyster

    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

    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

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

    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);

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] wp_create/wp_insert_category Undefined Error’ is closed to new replies.
Skip to toolbar