wp_update_category

函式
wp_update_category ( $catarr )
引數
  • (array) $catarr The 'cat_ID' value is required. All other keys are optional.
    Required:
返回值
  • (int|false) The ID number of the new or updated Category on success. Zero or FALSE on failure.
定義位置
相關方法
wp_create_categorywp_delete_categorywp_update_termwp_update_coreupdate_category_cache
引入
2.0.0
棄用
-

wp_update_category: 這個函式用來更新WordPress資料庫中的一個現有類別。它接收一個用於更新類別的引數陣列,例如它的名稱、lug、父類別和描述。

以最小的引數替代wp_insert_category()。

如果你只想更新一個現有類別的某些欄位,請在呼叫此函式時,只在$catarr內設定新的值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >