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 1


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

  1. In your View, add the OG membership: Group ID contextual filter (make sure it's first in the list).

  2. Under its settings under More, check Allow multiple values.

  3. Because some users may be in more than one group, go to Query settings under Other and check Distinct.

That should be it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.