BP_Groups_Group::search_groups( string $filter, int|null $limit = null, int|null $page = null, string|bool $sort_by = false, string|bool $order = false )
Get a list of groups, filtered by a search string.
Description
Parameters
- $filter
-
(Required) Search term. Matches against 'name' and 'description' fields.
- $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
- $sort_by
-
(Optional) Column to sort by. Default: false (default sort).
Default value: false
- $order
-
(Optional) ASC or DESC. Default: false (default sort).
Default value: false
Return
(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 search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) { $args = array( 'search_terms' => $filter, 'per_page' => $limit, 'page' => $page, 'orderby' => $sort_by, '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.