wpseek.com
WordPress开发者和主题制作者的搜索引擎



wp_create_category › WordPress Function

Since2.0.0
已弃用n/a
› wp_create_category ( $category_name, $category_parent = 0 )
参数: (2)
  • (string) $category_name Category name.
    Required: Yes
  • (int) $category_parent Optional. ID of parent category.
    Required: No
    默认: —
返回:
  • (int) The ID of category term on success, or zero on failure.
定义在:
文档:

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



源码

function wp_create_category( $category_name, $category_parent = 0 ) {
	$id = category_exists( $category_name, $category_parent );
	if ( $id ) {
		return (int) $id;
	}

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