I am new to organic groups, I ran into a problem, I am a member of some organic group, I need to list other members of same group on my profile page, Trying to display it using views but no luck :(, I am working on drupal 7 with Organic group 7.x-2.9
1 Answer
I forgot to answer you last time.! Sorry. You said your were happy with some code so here it is.
Step 1: The custom module.
function CUSTOM_MODULE_views_pre_view(&$view, &$display_id, &$args){
// Select our view
if($view->name == 'VIEW_NAME' and $display_id == 'DISPLAY_NAME') {
// Get User ID from url
$view_user = user_load(arg(1));
$user_groups = array();
// Get Group IDs
$items = field_get_items('user', $view_user, 'og_user_node');
foreach($items as $item) {
$user_groups[] = $item['target_id'];
}
// Join like 4+78+345 for Views
$user_groups_args = implode("+", $user_groups);
// Send IDs to view
$args[0] = $user_groups_args;
}
}
Create a module and change what's in caps. Be aware that that module doesn't do any checking.. Only use it for user/* or node/* etc. where the second argument is an integer.
Step 2: The View
In your View, add the
OG membership: Group ID
contextual filter (make sure it's first in the list).Under its settings under More, check
Allow multiple values
.Because some users may be in more than one group, go to
Query settings
underOther
and checkDistinct
.
That should be it.