wp_create_category

函数


wp_create_category ( $cat_name, $category_parent = 0 )
参数
  • (int|string)
    $cat_name
    Category name.
    Required:
  • (int)
    $category_parent
    Optional. ID of parent category.
    Required:
返回值
  • (int|WP_Error)
定义位置
  • wp-admin/includes/taxonomy.php
    , line 55
引入
2.0.0
弃用

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

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,
		)
	);
}