WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/wp insert category

Contents

Description

Inserts a new category into the taxonomy system.

Usage

<?php wp_insert_category$catarr$wp_error ); ?>

Parameters

$catarr
(array) (required) Category information.
Default: None
$catarr is checked against an array with the following default values:
$cat_defaults = array(
  'cat_ID' => 0,
  'cat_name' => ,
  'category_description' => ,
  'category_nicename' => ,
  'category_parent' => ,
  'taxonomy' => 'category' );
$catarr may contain additional values, but it is reccomended that you provide at least the minimum of those defined in $cat_defaults.
$wp_error
(boolean) (optional) Whether to return a WP_Error or a boolean. Boolean by default.
Default: false

Return Values

(boolean | WP_Error | int) 
True on success and false on failure OR a WP_Error on failure and the Category ID of the new category on true.

Examples

To insert a new category use:

%%%//Define the category
$my_cat = array('cat_name' => 'My Category', 'category_description' => 'A Cool Category', 'category_nicename' => 'category-slug', 'category_parent' => '');

// Create the category
$my_cat_id = wp_insert_category($my_cat);

Notes

  • Not all possible members of the $catarr array are listed here.
  • See wp_create_category() for a simpler version which takes just a string instead of an array.

Source File

wp_insert_category() is located in wp-admin/includes/taxonomy.php.

Related

See also index of Function Reference and index of Template Tags.