how is it possible that using wp_insert_category throw a fatal error ?
I am using it as explained : http://codex.wordpress.org/Function_Reference/wp_insert_category
with no change except:
$cat_defaults = array(
'cat_name' => 'some_name',
'category_description' => 'as asdfasdf sdf adfa fas f',
'category_nicename' => '',
'category_parent' => '',
'taxonomy' => 'category'
);
$someSome = wp_insert_category($cat_defaults);
i dont know if its relevant however i execute it on add_action( 'init', array($this, 'registerCustoms') );
And i get the following error :
Fatal error: Call to undefined function wp_insert_category() in /home1/stodeckc/public_html/podio-wp-sync/wp-content/plugins/podio_management/libs/appSync/appSync_custom.php on line 61
Any ideas?
The
init
action is the wrong place. This is becauseinit
runs on all requests, admin or front-end, but thewp_insert_category
function is an admin-side only function. You generally don’t insert categories from the front end.Move to a more specific action, one that will be run in the admin side. Probably from your plugin’s admin pages.
If you used
wp_insert_category
on Front, you must add this:you have to use hook admin init
And that’s it
I think here is not required to admin_init, because this also define on taxonomy.php
So please use on this way: