Function: wp_set_post_tags

wp_set_post_tags( integer $post_id, string | array $tags, boolean $append )

Set the tags for a post.

Shortcut: wspt

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.


Name Type(s) Default Value Description
$post_id integer

Optional. The Post ID. Does not default to the ID of the global $post.

$tags string | array ''

Optional. An array of tags to set for the post, or a string of tags separated by commas. Default empty.

$append boolean false

Optional. If true, don't delete existing tags, just add on. If false, replace the tags with the new tags. Default false.


array | false | WP_Error

Array of term taxonomy IDs of affected terms. WP_Error or false on failure.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.