WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Not able to create new category via script

[Resolved] Not able to create new category via script

  • fuliggians
    Participant

    @fuliggians

    Hi,

    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:

    require_once(‘…\wp-config.php’);
    require_once(‘…\wp-includes\wp-db.php’);
    require_once(‘…\wp-includes\taxonomy.php’);

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

    thanks
    D

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

    fuliggians
    Participant

    @fuliggians

    ach, forgot admin!
    thanks so much!

    WebTechGlobal
    Participant

    @webtechglobal

    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?!

    wp_insert_category
    wp_create_category

    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.

    Ryan

    I was having a similar problem with wp_create_category until I read this post: http://wordpress.org/support/topic/301982?replies=4

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