WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
what i found out so far: when i use 'cat_ID' => array(3352), it doenst give me the error msg but it creates a category with the ID 1. Probably because there is one value in the array. Any ideas? – karunin Dec 19 '13 at 5:31
If you are creating a category, why you are passing the cat_ID value? – Chittaranjan Dec 19 '13 at 7:09
Yeah I actually realized that it is not possible to give an id if you create a new category. The codex is not so clear on this and I didn't know. I have a solution now and will post as soon as the system lets me. – karunin Dec 19 '13 at 7:34

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

$my_cat = array(
    'cat_name' => 'Community News & Views', 
    'category_nicename' => 'news', 
    'taxonomy' => 'category'
$my_cat_id = wp_insert_category($my_cat);

In a second step I create the child categories using

    $parent_term = term_exists( 'news', 'category' );
$parent_term_id = $parent_term['term_id'];
$my_cat = array(
    'cat_name' => 'Business Articles', 
    'category_nicename' => 'business-articles', 
    'category_parent' => $parent_term_id,
    'taxonomy' => 'category'
$my_cat_id = wp_insert_category($my_cat);

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.

share|improve this answer

Try to use wp_insert_term() in place of wp_insert_category(). You can use the following code:

 'Newcastle Community News & Views', 
share|improve this answer
I tried this, but it doesn't work either. You are not supposed to give id's when creating new stuff. The codex is not so clear on this and I didn't know. I have a solution now and will post as soon as the system lets me. – karunin Dec 19 '13 at 7:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.