wp_create_term()
Adds a new term to the database if it does not already exist.
No Hooks.
Return
Array|WP_Error
.
Usage
wp_create_term( $tag_name, $taxonomy );
- $tag_name(string) (required)
- The term name.
- $taxonomy(string)
- The taxonomy within which to create the term.
Default: 'post_tag'
Changelog
Since 2.8.0 | Introduced. |
wp_create_term() wp create term code WP 6.5.2
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 ); }