为给定的帖子创建类别。
原型
wp_create_categories( array $categories, int $post_id = '' )
参数
$categories
(array)
(Required)
要创建的类别列表。
$post_id
(int)
(Optional)
帖子ID。
返回值
(array)
为给定帖子创建的类别列表。
源文件
路径:wp-admin/includes/taxonomy.php
<?php
...
function wp_create_categories( $categories, $post_id = '' ) {
$cat_ids = array ();
foreach ( $categories as $category ) {
if ( $id = category_exists( $category ) ) {
$cat_ids[] = $id;
} elseif ( $id = wp_create_category( $category ) ) {
$cat_ids[] = $id;
}
}
if ( $post_id )
wp_set_post_categories($post_id, $cat_ids);
return $cat_ids;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_create_categories/