HI Francois,
It shouldn’t be difficult.
You need to pull the member IDs belong to the group that you want to display and modify the members query to include only these member IDs.
Try the script below. Add it to the functions.php file of your theme and change the form ID ( 1 ) and group id ( 6 ) based on your needs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function gmw_filter_members_by_group ( $ args , $ gmw ) {
//verify the form ID. Change the value 1 to the ID of the form that you want to modify.
if ( $ gmw [ 'ID' ] ! = 1 )
return $ args ;
global $ wpdb ;
//pull member IDs from databse based on group ID. Change the number 6 to the group ID that you wish to use.
$ member_ids = $ wpdb -> get_col ( "SELECT user_id FROM {$wpdb->prefix}bp_groups_members WHERE group_id = 6 AND is_confirmed = 1" ) ;
//create member IDs array
$ member_ids = implode ( ',' , $ member_ids ) ;
//modify the 'include' query args based on the member IDs.
$ args [ 'include' ] = $ member_ids ;
//return the modified args
return $ args ;
}
add_filter ( 'gmw_fl_search_query_args' , 'gmw_filter_members_by_group' , 20 , 2 ) ;
Let me know if that helps.