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 add object terms

Description

Add term(s) associated with a given object. Wrapper for wp_set_object_terms().

Parameters

$object_id
(int) (required) The ID of the object to which the terms will be added.
Default: None
$terms
(mixed) (required) The slug(s) or ID(s) of the term(s) to add. Accepts array, int or string.
Default: None
$taxonomy
(mixed) (required) The taxonomy name. Accepts array or string.
Default: None

Return

(mixed) 
An array of affected term IDs, WP_Error otherwise.

Usage

 <?php wp_add_object_terms$id$terms$taxonomy ); ?> 

Example

Set categories for an attachment.

wp_add_object_terms( $attachment_id, 'Uncategorized', 'category' );

Change Log

Source File

wp_add_object_terms() is located in wp-includes/taxonomy.php.

Related

wp_set_object_terms()