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 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 See also

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

Top ↑

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'


Top ↑

Return Return

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


Top ↑

Source 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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.