wp_set_post_tags

Set the tags for a post.

Description

(array|false|WP_Error) wp_set_post_tags( (int) $post_id = 0, (string) $tags = '', (bool) $append = false ); 

Returns (array|false|WP_Error)

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

Parameters (3)

0. $post_id — Optional. (int)
The Post ID. Does not default to the ID of the global $post.
1. $tags — Optional. (string) => ''
An array of tags to set for the post, or a string of tags separated by commas. Default empty.
2. $append — Optional. (bool) => false
If true, don't delete existing tags, just add on. If false, replace the tags with the new tags. Default false.

Usage

  1. if ( !function_exists( 'wp_set_post_tags' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. The Post ID. Does not default to the ID of the global $post. 
  5. $post_id = -1; 
  6.  
  7. // Optional. An array of tags to set for the post, or a string of tags 
  8. // separated by commas. Default empty. 
  9. $tags = ''; 
  10.  
  11. // Optional. If true, don't delete existing tags, just add on. If false, 
  12. // replace the tags with the new tags. Default false. 
  13. $append = false; 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = wp_set_post_tags($post_id, $tags, $append); 
  17.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { 
  2. return wp_set_post_terms( $post_id, $tags, 'post_tag', $append);