wp_create_category() – Add a new category to the database if it does not already exist.

You appear to be a bot. Output may be restricted

Description

Adds a new category to the database if it does not already exist.

Usage

$int|WP_Error = wp_create_category( $cat_name, $category_parent );

Parameters

$cat_name
( int|string ) required – Category name.
$category_parent
( int ) optional – Optional. ID of parent category.

Returns

int|WP_Error

Source

File name: wordpress/wp-admin/includes/taxonomy.php
Lines:

1 to 13 of 13
function wp_create_category( $cat_name, $category_parent = 0 ) {
  $id = category_exists( $cat_name, $category_parent );
  if ( $id ) {
    return $id;
  }

  return wp_insert_category(
    array(
      'cat_name'        => $cat_name,
      'category_parent' => $category_parent,
    )
  );
}
 

 View on GitHub View on Trac