groups_get_groups( array|string $args = '' )
Get a collection of groups, based on the parameters passed.
Description
Parameters
- $args
-
(Optional) Array of arguments. Supports all arguments of BP_Groups_Group::get(). Where the default values differ, they have been described here.
- 'per_page'
(int) Default: 20. - 'page'
(int) Default: 1.
Default value: ''
- 'per_page'
Return
(array) See BP_Groups_Group::get().
Source
File: bp-groups/bp-groups-functions.php
function groups_get_groups( $args = '' ) {
$defaults = array(
'type' => false, // Active, newest, alphabetical, random, popular.
'order' => 'DESC', // 'ASC' or 'DESC'
'orderby' => 'date_created', // date_created, last_activity, total_member_count, name, random, meta_id.
'user_id' => false, // Pass a user_id to limit to only groups that this user is a member of.
'include' => false, // Only include these specific groups (group_ids).
'exclude' => false, // Do not include these specific groups (group_ids).
'parent_id' => null, // Get groups that are children of the specified group(s).
'slug' => array(), // Find a group or groups by slug.
'search_terms' => false, // Limit to groups that match these search terms.
'search_columns' => array(), // Select which columns to search.
'group_type' => '', // Array or comma-separated list of group types to limit results to.
'group_type__in' => '', // Array or comma-separated list of group types to limit results to.
'group_type__not_in' => '', // Array or comma-separated list of group types that will be excluded from results.
'meta_query' => false, // Filter by groupmeta. See WP_Meta_Query for syntax.
'show_hidden' => false, // Show hidden groups to non-admins.
'status' => array(), // Array or comma-separated list of group statuses to limit results to.
'per_page' => 20, // The number of results to return per page.
'page' => 1, // The page to return if limiting per page.
'update_meta_cache' => true, // Pre-fetch groupmeta for queried groups.
'update_admin_cache' => false,
'fields' => 'all', // Return BP_Groups_Group objects or a list of ids.
);
$r = bp_parse_args( $args, $defaults, 'groups_get_groups' );
$groups = BP_Groups_Group::get( array(
'type' => $r['type'],
'user_id' => $r['user_id'],
'include' => $r['include'],
'exclude' => $r['exclude'],
'slug' => $r['slug'],
'parent_id' => $r['parent_id'],
'search_terms' => $r['search_terms'],
'search_columns' => $r['search_columns'],
'group_type' => $r['group_type'],
'group_type__in' => $r['group_type__in'],
'group_type__not_in' => $r['group_type__not_in'],
'meta_query' => $r['meta_query'],
'show_hidden' => $r['show_hidden'],
'status' => $r['status'],
'per_page' => $r['per_page'],
'page' => $r['page'],
'update_meta_cache' => $r['update_meta_cache'],
'update_admin_cache' => $r['update_admin_cache'],
'order' => $r['order'],
'orderby' => $r['orderby'],
'fields' => $r['fields'],
) );
/**
* Filters the collection of groups based on parsed parameters.
*
* @since BuddyPress 1.2.0
*
* @param BP_Groups_Group $groups Object of found groups based on parameters.
* Passed by reference.
* @param array $r Array of parsed arguments used for group query.
* Passed by reference.
*/
return apply_filters_ref_array( 'groups_get_groups', array( &$groups, &$r ) );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.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.