WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp set post tags

Description

Set tags for a post. Every tag that does not already exists will be automatically created. Uses wp_set_post_terms().

Usage

<?php wp_set_post_tags$post_ID$tags$append ?>

Parameters

$post_ID
(integer) (required) Post ID.
Default: 0
$tags
(string,array) (optional) List of tags. Can be an array or a comma separated string.
Default: array
$append
(boolean) (optional) If true, tags will be appended to the post. If false, tags will replace existing tags.
Default: false

Return Values

(boolean|null) 

Will return false if $post_id is not an integer or is 0. Will return null otherwise.

Examples

To add the tags meaning and life to the current tags of the post with ID 42:

wp_set_post_tags( 42, 'meaning,life', true );


Notes

Hooks

Change Log

Since: 2.3.0

Source File

wp_set_post_tags() is located in wp-includes/post.php.

Related

wp_insert_term wp_delete_term wp_set_post_terms

See also index of Function Reference and index of Template Tags.