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

Set taxonomy terms on a BuddyPress object.

Description

See also

Parameters

$object_id

(Required) Object ID.

$terms

(Required) Term or terms to set.

$taxonomy

(Required) Taxonomy name.

$append

(Optional) True to append terms to existing terms. Default: false.

Default value: false

Return

(array) Array of term taxonomy IDs.

Source

File: bp-core/bp-core-taxonomy.php

function bp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
	$site_id = bp_get_taxonomy_term_site_id( $taxonomy );

	$switched = false;
	if ( $site_id !== get_current_blog_id() ) {
		switch_to_blog( $site_id );
		bp_register_taxonomies();
		$switched = true;
	}

	$tt_ids = wp_set_object_terms( $object_id, $terms, $taxonomy, $append );

	if ( $switched ) {
		restore_current_blog();
	}

	/**
	 * Fires when taxonomy terms have been set on BuddyPress objects.
	 *
	 * @since BuddyPress 2.7.0
	 *
	 * @param int    $object_id Object ID.
	 * @param array  $terms     Term or terms to remove.
	 * @param array  $tt_ids    Array of term taxonomy IDs.
	 * @param string $taxonomy  Taxonomy name.
	 */
	do_action( 'bp_set_object_terms', $object_id, $terms, $tt_ids, $taxonomy );

	return $tt_ids;
}

Changelog

Changelog
Version Description
BuddyPress 2.2.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.