I have simple code:

add_action('init', 'categoryTransfer');

function categoryTransfer(){
//some code
    for($i=0; $i < count($categories); $i++)

But when it executes i get:

Fatal error: Call to undefined function wp_create_category() in /Users/noname/Sites/wp-content/plugins/my_plugin/my_plugin.php on line 95

Where is a problem?

1 Answer 1


This function is declared in wp-admin/includes/taxonomy.php.
This file will be loaded in wp-admin/includes/admin.php.
And that now is called in wp-admin/admin.php.

So the solution is: Use the hook 'admin_init' or require all necessary files manually. But don’t do that on every request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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