WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Not able to create new category via script (5 posts)

  1. fuliggians
    Member
    Posted 5 years ago #

    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

  2. MichaelH
    Member
    Posted 5 years ago #

    Function is in wp-admin/includes/taxonomy.php

  3. fuliggians
    Member
    Posted 5 years ago #

    ach, forgot admin!
    thanks so much!

  4. WebTechGlobal
    Member
    Posted 5 years ago #

    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

  5. zsiswick
    Member
    Posted 4 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags