WordPress.org

Ready to get started?Download WordPress

Codex

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

Difference between revisions of "Function Reference/wp add object terms"

m (Return)
(Add function info from phpdoc)
Line 1: Line 1:
 
==Description==
 
==Description==
  +
Add term(s) associated with a given object. Wrapper for [[Function_Reference/wp_set_object_terms|wp_set_object_terms()]].
   
 
==Parameters==
 
==Parameters==
{{Parameter|$var|TYPE|Description.}}
+
{{Parameter|$object_id|int|The ID of the object to which the terms will be added.}}
{{Parameter|$var|TYPE|Description.|optional|DEFAULT}}
+
{{Parameter|$terms|mixed|The slug(s) or ID(s) of the term(s) to add. Accepts array, int or string.}}
  +
{{Parameter|$taxonomy|mixed|The taxonomy name. Accepts array or string.}}
   
 
== Return ==
 
== Return ==
{{Return||TYPE|Description.}}
+
{{Return||mixed|An array of affected term IDs, WP_Error otherwise.}}
   
 
== Usage ==
 
== Usage ==
%%% <?php ?> %%%
+
%%% <?php wp_add_object_terms( $id, $terms, $taxonomy ); ?> %%%
   
 
==Example==
 
==Example==
Description text
+
Set categories for an attachment.
  +
 
<pre>
 
<pre>
Example code
+
wp_add_object_terms( $attachment_id, 'Uncategorized', 'category' );
 
</pre>
 
</pre>
   
Line 22: Line 23:
 
== Source File ==
 
== Source File ==
 
<!-- Need links to current source code files -->
 
<!-- Need links to current source code files -->
<tt>wp_add_object_terms()</tt> is located in {{Trac|wp-whatever/file.php}}.
+
<tt>wp_add_object_terms()</tt> is located in {{Trac|wp-includes/taxonomy.php}}.
   
 
==Related==
 
==Related==
Function ref links
+
[[Function_Reference/wp_set_object_terms|wp_set_object_terms()]]
   
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{Copyedit}}
 

Revision as of 16:21, 18 May 2013

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()