Adds a new term to the database. Optionally marks it as an alias of an existing term.

wp_insert_term() 描述


<?php wp_insert_term$term$taxonomy$args = array() ); ?>

wp_insert_term() 用法



(int|string) (必填) The term to add or update.

默认值: None


(string) (必填) The taxonomy to which to add the term.

默认值: None


(array|string) (可选) Change the values of the inserted term

默认值: None


The arguments decide how the term is handled based on the $args parameter. The following is a list of the available overrides and the defaults.


(string) (可选) There is no default, but if added, expected is the slug that the term will be an alias of.

默认值: None


(string) (可选) If exists, will be added to the database along with the term.

默认值: None


(numeric) (可选) Will assign value of 'parent' to the term.

默认值: 0 (zero)


(string) (可选)

默认值: None

If 'slug' argument exists then the slug will be checked to see if it is not a valid term. If that check succeeds (it is not a valid term), then it is added and the term id is given. If it fails, then a check is made to whether the taxonomy is hierarchical and the parent argument is not empty. If the second check succeeds, the term will be inserted and the term id will be given. If the slug argument is empty, then it will be calculated from the term name.

wp_insert_term() 参数



The Term ID and Term Taxonomy ID. (Example: array('term_id'=>12,'term_taxonomy_id'=>34))

Error handling is assigned for the nonexistence of the $taxonomy and $term parameters before inserting. If both the term id and taxonomy exist previously, then an array will be returned that contains the term id and the contents of what is returned. The keys of the array are 'term_id' and 'term_taxonomy_id' containing numeric values.

It is assumed that the term does not yet exist or the above will apply. The term will be first added to the term table and then related to the taxonomy if everything is well. If everything is correct, then several actions will be run prior to a filter and then several actions will be run after the filter is run.

wp_insert_term() 返回值


添加于 版本: 2.3.0

wp_insert_term() 历史


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

wp_insert_term() 源文件