Core Function
View Source on Trac ↗ wp_set_post_terms()
wp_set_post_terms(
mixed $post_id = 0,
mixed $terms = '',
mixed $taxonomy = 'post_tag',
mixed $append = false
) Sets the terms for a post.
Parameters 2 required
| Name / Type | Description |
|---|---|
| $post_id int | Optional. The Post ID. Does not default to the ID of the global $post. |
| mixed | (string | array) $terms Optional. An array of terms to set for the post, or a string of terms separated by commas. Hierarchical taxonomies must always pass IDs rather than names so that children with the same names but different parents aren't confused. Default empty. Required |
| $taxonomy string | Optional. Taxonomy name. Default 'post_tag'. |
| bool | $append Optional. If true, don't delete existing terms, just add on. If false, replace the terms with the new terms. Default false. Required |
Return Value
((array)
| false | WP_Error) Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
Function Information
Since Version
2.8.0
Source File
wp-includes/post.php
Advertisement