ok, after abit of digging I found away that might work.
Buddypress seems to WP_User_Query for the members query, so I can filter on pre_get_users
what I’m going todo is run a query where to find all users what are in a group that search term matches e.g. (pseudo query haven’t looked at the tables yet)
select ids_of_users from users, groups
where group_name like ‘%SEARCH_TERM%’ (join users and groups)
Then from the ids above I can do something like this:
$query->set( ‘include’, (array) $user_ids );
looks like that should work, but welcome any input.
update: I wrote the code. It all seems to work fine (except), it doesn’t seem to affect the query (i.e. the results in members index page are not right). Not sure why ?
Any input would be hugely appreciated:
function add_groups_to_members_search( $query_args ) {
$search = esc_sql($_REQUEST['search_terms']); // search box on members index page
global $wpdb;
// get users in groups that search term is like
$sql = "SELECT m.user_id FROM wp_bp_groups g, wp_bp_groups_members m where g.id = m.group_id and g.name like '%$search%'";
$myrows = $wpdb->get_results( $sql );
$user_ids = array();
foreach ($myrows as $obj ) {
$user_ids[] = $obj->user_id;
}
$query_args['include'] = $user_ids;
return $query_args;
}
add_filter( 'bp_before_has_members_parse_args', 'add_groups_to_members_search', 999999, 1 );
@louie171 You can use a standard loop instead of direct SQL queries
Group Members Loop