bp_get_term_by

Get term data for terms in BuddyPress taxonomies.

Description

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

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.

Returns (WP_Term|bool)

WP_Term instance on success. Will return false if `$taxonomy` does not exist or `$term` was not found.

Parameters (5)

0. $field (string)
Either slug,, name , id (term_id), or term_taxonomy_id
1. $value (string|int)
Search for this term value
2. $taxonomy — Optional. (string) => ''
Taxonomy name. Optional, if $field is term_taxonomy_id..
3. $output — Optional. (constant) => OBJECT
Constant OBJECT, ARRAY_A, or ARRAY_N
4. $filter — Optional. (string) => 'raw'
Optional, default is raw or no WordPress defined filter will applied.

Usage

  1. if ( !function_exists( 'bp_get_term_by' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-taxonomy.php'; 
  3.  
  4. // Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id' 
  5. $field = ''; 
  6.  
  7. // Search for this term value 
  8. $value = null; 
  9.  
  10. // Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'. 
  11. $taxonomy = ''; 
  12.  
  13. // Constant OBJECT, ARRAY_A, or ARRAY_N 
  14. $output = OBJECT; 
  15.  
  16. // Optional, default is raw or no WordPress defined filter will applied. 
  17. $filter = 'raw'; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = bp_get_term_by($field, $value, $taxonomy, $output, $filter); 
  21.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-taxonomy.php  
  1. function bp_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { 
  2. $site_id = bp_get_taxonomy_term_site_id( $taxonomy ); 
  3.  
  4. $switched = false; 
  5. if ( $site_id !== get_current_blog_id() ) { 
  6. switch_to_blog( $site_id ); 
  7. $switched = true; 
  8.  
  9. $term = get_term_by( $field, $value, $taxonomy, $output, $filter ); 
  10.  
  11. if ( $switched ) { 
  12.  
  13. return $term;