WordPress插入分类法函数:wp_insert_term

2022/07/12

WordPress函数wp_insert_term用于插入一个分类法项目

wp_insert_term( string $term, string $taxonomy, array|string $args = array() )

本文涉及的内容包括:

函数参数

$term

字符串

分类名称

$taxonomy

字符串

分类法名称

$args

数组或字符串

分类的参数,可用值如下:

  • alias_of:别名;
  • description:分类的简要描述;
  • parent:如果指定分类法支持层级,可以对创建的分类指定父分类;
  • slug:别名。

函数返回值

插入分类成功返回包含term_id和term_taxonomy_id的数组,失败返回WP_Error

函数使用示例

wp_insert_term('图书', 'product', array(
        'description' => '图书分类描述',
        'slug'        => 'books',
        'parent'      => 1,
    )
);

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注