wp_add_post_tags

Add tags to a post.

Description

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

Returns (array|false|WP_Error)

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

Parameters (2)

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.

Usage

  1. if ( !function_exists( 'wp_add_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. // NOTICE! Understand what this does before running. 
  12. $result = wp_add_post_tags($post_id, $tags); 
  13.  

Defined (1)

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

/wp-includes/post.php  
  1. function wp_add_post_tags( $post_id = 0, $tags = '' ) { 
  2. return wp_set_post_tags($post_id, $tags, true);