别名wp_insert_category()使用最小的args。
原型
wp_update_category( array $catarr )
描述
如果你只想更新现有类别的某些字段,请仅使用$ catarr中设置的新值调用此函数。
参数
$catarr
(array)
(Required)
‘cat_ID’值是必需的。所有其他键都是可选的。
返回值
(int|bool)
成功时新的或更新的类别的ID号。失败时为零或假。
源文件
路径:wp-admin/includes/taxonomy.php
<?php
...
function wp_update_category($catarr) {
$cat_ID = (int) $catarr['cat_ID'];
if ( isset($catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) )
return false;
// First, get all of the original fields
$category = get_term( $cat_ID, 'category', ARRAY_A );
_make_cat_compat( $category );
// Escape data pulled from DB.
$category = wp_slash($category);
// Merge old and new fields with new fields overwriting old ones.
$catarr = array_merge($category, $catarr);
return wp_insert_category($catarr);
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_update_category/