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



wp_create_category › WordPress Function

Since2.0.0
已弃用n/a
wp_create_category ( $cat_name, $category_parent = 0 )
参数: (2)
  • (int|string) $cat_name Category name.
    Required: Yes
  • (int) $category_parent Optional. ID of parent category.
    Required: No
    默认:
返回:
  • (int|WP_Error)
定义在:
文档:

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