Title: Call to undefined function wp_create_category()
Last modified: July 31, 2021

---

# Call to undefined function wp_create_category()

 *  [otto2021](https://wordpress.org/support/users/otto2021/)
 * (@otto2021)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_create_category/)
 * Hello,
 * I’m sorry, I speak a little English.
 * My custom theme:
 * ~/wp-content/themes/mycustomtheme/functions.php
 *     ```
       function mct_task() {
       	include( get_template_directory() . '/inc/cron.php' );
       }
       add_action( 'mct_hook', 'mct_task' );
       //
       function mytheme_setup_options() {
       	if( ! wp_next_scheduled( 'mct_hook' ) ) {
       		wp_schedule_event( time(), 'hourly', 'mct_hook' );
       	} else {}
       }
       add_action( 'after_switch_theme', 'mytheme_setup_options' );
       ```
   
 * ~/wp-content/themes/mycustomtheme/inc/cron.php
 *     ```
       $category_id = wp_create_category( 'Super' );
       // $my_post = array( 'post_category'=> array( $category_id ) );
       wp_insert_post( $my_post );
       ```
   
 * ~/error_log
 * `PHP Fatal error: Uncaught Error: Call to undefined function wp_create_category()
   in...`
 * Why? What is the problem?
 * I would like use category at wp_insert_post with wp-cron. If the category exists,
   use the category ID, if not exists, create new category.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [otto2021](https://wordpress.org/support/users/otto2021/)
 * (@otto2021)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_create_category/#post-14722660)
 * `PHP Fatal error: Uncaught Error: Call to undefined function wp_insert_category()
   in...`
 * No comment. I was disappointed in WordPress.
 *  Thread Starter [otto2021](https://wordpress.org/support/users/otto2021/)
 * (@otto2021)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_create_category/#post-14722672)
 * Bad idea:
 *     ```
       wp_create_category();
       wp_insert_category();
       ```
   
 * Good idea:
 * `wp_insert_term( 'Super', 'category' );`
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_create_category/#post-14722691)
 * The so called “bad” are essentially wrappers of the “good”. They are all interrelated.
   Any of them should work for you.
 * Typically when we get undefined function errors on standard WP functions, it’s
   because the WP environment was not correctly initiated for the request. cron.
   php needs to be included or required from your theme’s functions.php. Apparently
   something is directly requesting cron.php without initializing WP.
 * The way to use wp-cron is to schedule an event, which defines a certain action
   hook that will fire on schedule. You add callback functions to this hook to get
   code to execute. There are examples in the user notes near the bottom of the 
   docs page:
    [https://developer.wordpress.org/reference/functions/wp_schedule_event/](https://developer.wordpress.org/reference/functions/wp_schedule_event/)
 *  [Kian William](https://wordpress.org/support/users/kianwilliam/)
 * (@kianwilliam)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_create_category/#post-14726469)
 * From what I remember wp_create_category() has two arguments and both are required
   as this:
    wp_create_category(int/string $cat_name, int $parent) Kian William

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Call to undefined function wp_create_category()’ is closed to new replies.

## Tags

 * [wp_create_category](https://wordpress.org/support/topic-tag/wp_create_category/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 3 participants
 * Last reply from: [Kian William](https://wordpress.org/support/users/kianwilliam/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_create_category/#post-14726469)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
