wp_create_category

函式
wp_create_category ( $cat_name, $category_parent = 0 )
引數
  • (int|string) $cat_name Category name.
    Required:
  • (int) $category_parent Optional. ID of parent category.
    Required:
返回值
  • (int|WP_Error)
定義位置
相關方法
wp_create_categorieswp_update_categorywp_delete_categorywp_create_termwp_insert_category
引入
2.0.0
棄用
-

wp_create_category: 這是一個建立新類別的函式。它可以用來以程式設計方式建立一個類別,而不是在WordPress儀表盤上手動建立。

在資料庫中新增一個新的類別,如果它還不存在的話。

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

常見問題

FAQs
檢視更多 >