I’m writing a plugin that automatically creates a bunch of stuff ie categories and child categories. But when I use the following code to create the categories: (from wp codex)
//Create Post Categories
$my_cat = array(
'cat_ID' => 1146,
'cat_name' => 'Newcastle Community News & Views',
'category_description' => '',
'category_nicename' => 'news',
'category_parent' => '',
'taxonomy' => 'category'
);
$my_cat_id = wp_insert_category($my_cat);
It gives me the following error.
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/newcastl/public_html/wp-includes/taxonomy.php on line 2535
With the id in ” isnt working either.
I have to set the ID so I can refer to it when using sub-cats.
Thanks!
Ok here is the solution I found:
You are not meant to set IDs when creating new objects like categories. Instead I created the parent categories first using something like
In a second step I create the child categories using
Note: You cannot create Parent and Child categories at the same time because the parent category has to exist, when you create the Child category
Note also:
term_exists( 'news', 'category' );
uses the $slug as first argument. The codex is not so clear on that one.Try to use wp_insert_term() in place of wp_insert_category(). You can use the following code: