Support » Fixing WordPress » Not able to create new category via script

  • Resolved fuliggians



    I need to add a function to create automatically a child category. I just create manually the parent category.

    I tried to use: wp_create_category but the include is not working.

    $post_id= 3;
    $cat_name = “week_3”;
    $post_categories_week = wp_create_category( $cat_name, $parent_cat_id );
    wp_set_post_categories( $post_id, $post_categories_week );

    the error message: Call to undefined function wp_create_category()
    BUT I just include:


    the documentation I found online said that this function should be in taxonomy.php, but I didn’t find in it. Why?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Function is in wp-admin/includes/taxonomy.php

    ach, forgot admin!
    thanks so much!

    Do you need to include those files for a plugin because I get the same error SOMETIMES but sometimes it works in my plugin!

    To me thats just strange it can’t be defined sometimes and not other times can it so is there something that sometimes does not include these files as standard and that is the issue possible?!


    same happens with both of these. Funny thing is I have it in 2 places in my script within different if statements ok and if the other instance is called, it works fine I think.Need to confirm however but it has worked thats the main puzzling issue so any help is great.


    I was having a similar problem with wp_create_category until I read this post:

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Not able to create new category via script’ is closed to new replies.