I am trying to create category from WordPress plugin. Here is my code:
$id = wp_create_category('Category_name', 2);
But i am getting this error:
Missing argument 4 for wp_insert_term(), called in taxonomy.php on line 144 and defined in taxonomy.php on line 2226
But i am not using function wp_insert_term()
anywhere. Please help me. What i am doing wrong? is there anything extra which i have to do in plugin to make it working?
Thanks in advance
try to use wp_insert_category as wp_create_category is just a wrapper for it.
Passing a category ID means you're trying to create a child category, so make sure that a category with and ID of 2
exists.
If you do have a category with an ID of 2
, try omitting that param and seeing what happens. If your still getting an error after that, check what version of PHP you are using and update it.
If you're making a plugin to add a category to the database you will be better off using wp_insert_category() as it gives you more control.