• Resolved tiszenkel

    (@tiszenkel)


    So I’m developing a PHP script to run on top of a WordPress installation, the idea being to import content from a third party into WordPress on a regular basis. So far, things have been going great. The script is up to nearly 400 lines now, and anything I’ve wanted to do with WordPress, I’ve been able to do with no problem. All I did was include this code at the very top:

    if ( !isset($wp_did_header) ) {
    	$wp_did_header = true;
    	require_once( dirname(__FILE__) . '/wp-load.php' );
    	wp();
    }

    And I’ve been able to use lots of WordPress functions to automatically create posts, edit posts, add metadata to posts, delete posts, you name it.

    Until now. I ran into a weird snag, and I can’t figure out what’s different here. I am simply trying to do this:

    wp_create_category('Test category');

    Nothing. It simply doesn’t work. The script stops executing when it gets to that line.

    Though wp-load.php has presumably been taking care of this for me, I also tried specifically including taxonomy.php, wp-admin.php and wp-config.php. But no luck. Same results.

    Any idea what’s so special about wp_create_category and what I should be doing here?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tiszenkel

    (@tiszenkel)

    An update: wp_create_category fails even when I use it inside my theme. The plot thickens.

    Thread Starter tiszenkel

    (@tiszenkel)

    Another update: I tried wp_create_category on a completely different WordPress install, on a different server owed by a different company, using the default theme with no plugins enabled, and it still didn’t work. I find it so strange that WordPress has this fully documented function that simply doesn’t work. Nothing about it being deprecated or anything. Google reveals that a few other people have had issues, too, but nobody has any real answers, and I can’t find any reports of anyone successfully using it, not recently, at least. It seems like this should be a pretty commonly used function, right?

    Luckily, I was able to find an alternative: wp_insert_category.

    $parent_term = term_exists( 'Parent Category', 'category' );
    $parent_term_id = $parent_term['term_id'];
    wp_insert_term(
      'Child Category', // the term
      'category', // the taxonomy
      array(
        'parent'=> $parent_term_id
      )
    );

    If anyone’s having the same issue I was, there’s your answer.

    You are not alone tiszenkel,
    I have some problem with wp_create_category and stop working on it when I found this thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_create_category not working’ is closed to new replies.