On this page
wp_create_term( string $tag_name, string $taxonomy = 'post_tag' ): array|WP_Error
Adds a new term to the database if it does not already exist.
Parameters
$tag_namestring Required-
The term name.
$taxonomystring Optional-
The taxonomy within which to create the term. Default
'post_tag'.Default:
'post_tag'
Return
array|WP_Error
Source
File: wp-admin/includes/taxonomy.php. View all references
function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
$id = term_exists( $tag_name, $taxonomy );
if ( $id ) {
return $id;
}
return wp_insert_term( $tag_name, $taxonomy );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_insert_term() wp-includes/taxonomy.php | Adds a new term to the database. |
| term_exists() wp-includes/taxonomy.php | Determines whether a taxonomy term exists. |
Used By
| Used By | Description |
|---|---|
| wp_create_tag() wp-admin/includes/taxonomy.php | Adds a new tag to the database if it does not already exist. |
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_create_term