BP_Groups_Group::filter_user_groups( string $filter, int $user_id, mixed $order = false, int|null $limit = null, int|null $page = null )
Get a list of a user’s groups, filtered by a search string.
Description
Parameters
- $filter
-
(Required) Search term. Matches against 'name' and 'description' fields.
- $user_id
-
(Required) ID of the user whose groups are being searched. Default: the displayed user.
- $order
-
(Optional) Not used.
Default value: false
- $limit
-
(Optional) The max number of results to return. Default: null (no limit).
Default value: null
- $page
-
(Optional) The page offset of results to return. Default: null (no limit).
Default value: null
Return
(false|array)
- 'groups'
(array) Array of matched and paginated group IDs. - 'total'
(int) Total count of groups matching the query.
Source
File: bp-groups/classes/class-bp-groups-group.php
public static function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
if ( empty( $user_id ) ) {
$user_id = bp_displayed_user_id();
}
$args = array(
'search_terms' => $filter,
'user_id' => $user_id,
'per_page' => $limit,
'page' => $page,
'order' => $order,
);
$groups = BP_Groups_Group::get( $args );
// Modify the results to match the old format.
$paged_groups = array();
$i = 0;
foreach ( $groups['groups'] as $group ) {
$paged_groups[ $i ] = new stdClass;
$paged_groups[ $i ]->group_id = $group->id;
$i++;
}
return array( 'groups' => $paged_groups, 'total' => $groups['total'] );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.6.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.