bp_get_term_by( string $field, string|int $value, string $taxonomy = '', string $output = OBJECT, string $filter = 'raw' )

Get term data for terms in BuddyPress taxonomies.

Description

Note that term data is from the bp_get_taxonomy_term_site_id(), which on some multisite configurations may not be the same as the current site.

See also

  • get_term_by(): for a full description of function and parameters.

Parameters

$field

(Required) Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id'

$value

(Required) Search for this term value

$taxonomy

(Optional) Taxonomy name. Optional, if $field is 'term_taxonomy_id'.

Default value: ''

$output

(Optional) Constant OBJECT, ARRAY_A, or ARRAY_N

Default value: OBJECT

$filter

(Optional) default is raw or no WordPress defined filter will applied.

Default value: 'raw'

Return

(WP_Term|bool) WP_Term instance on success. Will return false if $taxonomy does not exist or $term was not found.

Source

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

function bp_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) {
	$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;
	}

	$term = get_term_by( $field, $value, $taxonomy, $output, $filter );

	if ( $switched ) {
		restore_current_blog();
	}

	return $term;
}

Changelog

Changelog
Version Description
BuddyPress 2.7.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.