wp_create_category()通过代码创建一个分类

目录

描述

This function adds a "simple" category by specifying a category name and (optionally) a category parent.

wp_create_category() 描述

用法

<?php wp_create_category$cat_name$parent ); ?>

wp_create_category() 用法

参数

$cat_name

(string) (必填) Name for the new category.

默认值: None

$parent

(integer) (可选) Category ID of the parent category.

默认值: None

wp_create_category() 参数

返回值

(integer) 

0 on failure, category id on success.

wp_create_category() 返回值

示例

In order to create a simple category use:

To create a category that is a child of Uncategorized (or whatever category has the ID 0), use:

To get id of category created and put value in variable:

wp_create_category() 示例

注意

  • wp_create_category() is a thin wrapper around wp_insert_category().
  • Because this is a wrapper, it is not suitable for entering a complex custom taxonomy element.
  • If the category already exists, it is not duplicated. The ID of the original existing category is returned without error.

wp_create_category() 注意

源文件

wp_create_category() 函数的代码位于 wp-admin/includes/taxonomy.php.

wp_create_category() 源文件