wp_set_object_terms

SummerySummery

Create Term and Taxonomy Relationships.

Syntax

wp_set_object_terms( int $object_id, string|int|array $terms, string $taxonomy, bool $append = false )

DescriptionDescription

Relates an object (post, link etc) to a term and taxonomy type. Creates the term and taxonomy relationship if it doesn’t already exist. Creates a term if it doesn’t exist (using the slug).

A relationship means that the term is grouped in or belongs to the taxonomy. A term has no meaning until it is given context by defining which taxonomy it exists under.

ParametersParameters

$object_id

(int) (Required) The object to relate to.

$terms

(string|int|array) (Required) A single term slug, single term id, or array of either term slugs or ids. Will replace all existing related terms in this taxonomy. Passing an empty value will remove all related terms.

$taxonomy

(string) (Required) The context in which to relate the term to the object.

$append

(bool) (Optional) If false will delete difference of terms.

Default value: false

ReturnReturn

(array|WP_Error) Term taxonomy IDs of the affected terms or WP_Error on failure.

SourceSource

File: wp-includes/taxonomy.php


			

ChangelogChangelog

Changelog
Version Description
2.3.0 Introduced.
Scroll to Top