wp_add_object_terms

Add term(s) associated with a given object.

Description

(array|WP_Error) wp_add_object_terms( (int) $object_id, (array|int|string) $terms, (array|string) $taxonomy ); 

Returns (array|WP_Error)

Term taxonomy IDs of the affected terms.

Parameters (3)

0. $object_id (int)
The ID of the object to which the terms will be added.
1. $terms (array|int|string)
The slug(s) or ID(s) of the term(s) to add.
2. $taxonomy (array|string)
Taxonomy name.

Usage

  1. if ( !function_exists( 'wp_add_object_terms' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // The ID of the object to which the terms will be added. 
  5. $object_id = -1; 
  6.  
  7. // The slug(s) or ID(s) of the term(s) to add. 
  8. $terms = null; 
  9.  
  10. // Taxonomy name. 
  11. $taxonomy = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_add_object_terms($object_id, $terms, $taxonomy); 
  15.  

Defined (1)

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

/wp-includes/taxonomy.php  
  1. function wp_add_object_terms( $object_id, $terms, $taxonomy ) { 
  2. return wp_set_object_terms( $object_id, $terms, $taxonomy, true );