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



wp_create_category ›

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

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



源码

function wp_create_category( $cat_name, $parent = 0 ) {
	if ( $id = category_exists( $cat_name, $parent ) ) {
		return $id;
	}

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