Forum Replies Created
-
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 );
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.
thanks David, I think I’ll probably go with your suggestion and use the groups built-in directory page.
thanks David, I figured it out.
It would be good if https://codex.buddypress.org/developer/group-types/
continued the example at the top of the page i.e. teams eg mysite.com/groups/type/teams instead of ninja as lower on the page.
(note teams not team).
thanks ray I’ve detailed a code example of how I did this on my blog