bp_get_objects_in_term

Retrieve IDs of objects in valid taxonomies and terms for BuddyPress-related taxonomies.

Description

(WP_Error|array) bp_get_objects_in_term( (int|array) $term_ids, (string|array) $taxonomies, (array) $args = array() ); 

Note that object IDs are from the bp_get_taxonomy_term_site_id(),, which on some multisite configurations may not be the same as the current site.

Returns (WP_Error|array)

If the taxonomy does not exist, then WP_Error will be returned. On success, the array can be empty, meaning that there are no $object_ids found. When object IDs are found, an array of those IDs will be returned.

Parameters (3)

0. $term_ids (int|array)
Term id or array of term ids of terms that will be used.
1. $taxonomies (string|array)
String of taxonomy name or Array of string values of taxonomy names.
2. $args — Optional. (array) => array()
Change the order of the object_ids, either ASC or DESC.

Usage

  1. if ( !function_exists( 'bp_get_objects_in_term' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-taxonomy.php'; 
  3.  
  4. // Term id or array of term ids of terms that will be used. 
  5. $term_ids = null; 
  6.  
  7. // String of taxonomy name or Array of string values of taxonomy names. 
  8. $taxonomies = null; 
  9.  
  10. // Change the order of the object_ids, either ASC or DESC. 
  11. $args = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_get_objects_in_term($term_ids, $taxonomies, $args); 
  15.  

Defined (1)

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

/bp-core/bp-core-taxonomy.php  
  1. function bp_get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { 
  2. // Different taxonomies may be stored on different sites. 
  3. $taxonomy_site_map = array(); 
  4. foreach ( (array) $taxonomies as $taxonomy ) { 
  5. $taxonomy_site_id = bp_get_taxonomy_term_site_id( $taxonomy ); 
  6. $taxonomy_site_map[ $taxonomy_site_id ][] = $taxonomy; 
  7.  
  8. $retval = array(); 
  9. foreach ( $taxonomy_site_map as $taxonomy_site_id => $site_taxonomies ) { 
  10. $switched = false; 
  11. if ( $taxonomy_site_id !== get_current_blog_id() ) { 
  12. switch_to_blog( $taxonomy_site_id ); 
  13. $switched = true; 
  14.  
  15. $site_objects = get_objects_in_term( $term_ids, $site_taxonomies, $args ); 
  16. $retval = array_merge( $retval, $site_objects ); 
  17.  
  18. if ( $switched ) { 
  19.  
  20. return $retval;