BP_Groups_Member::get_recently_joined( int $user_id, int|bool $limit = false, int|bool $page = false, string|bool $filter = false )
Get the IDs of the groups of which a specified user is a member, sorted by the date joined.
Description
Parameters
- $user_id
-
(Required) ID of the user.
- $limit
-
(Optional) Max number of results to return. Default: false (no limit).
Default value: false
- $page
-
(Optional) Page offset of results to return. Default: false (no limit).
Default value: false
- $filter
-
(Optional) Limit results to groups whose name or description field matches search terms.
Default value: false
Return
(array)
- 'groups'
(array) Array of groups returned by paginated query. - 'total'
(int) Count of groups matching query.
Source
File: bp-groups/classes/class-bp-groups-member.php
public static function get_recently_joined( $user_id, $limit = false, $page = false, $filter = false ) { global $wpdb; $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = ''; $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id ); if ( !empty( $limit ) && !empty( $page ) ) $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); if ( !empty( $filter ) ) { $search_terms_like = '%' . bp_esc_like( $filter ) . '%'; $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like ); } if ( $user_id != bp_loggedin_user_id() ) $hidden_sql = " AND g.status != 'hidden'"; $bp = buddypress(); $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY m.date_modified DESC {$pag_sql}" ); $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_banned = 0 AND m.is_confirmed = 1 ORDER BY m.date_modified DESC" ); return array( 'groups' => $paged_groups, 'total' => $total_groups ); }
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.