I have Views, Context and OG installed on Drupal 7.

One of the default views is OG User Groups (/user-groups.) It is a content view that shows the user which groups they belong to.

I'm trying to create something similar, as a block (and therefore cannot use URL arguments.) I want a user view that shows all of the users from the logged in user's group.

In Views, it would make sense that I get the user ID from the logged in user as a contextual filter and then perhaps pass it as an entity ID (etid) to get the group ID (gid). But no matter what I do I cannot make a view that allows this to happen.

Does anyone know I can get the group ID from the current logged in user to use in this view?


3 Answers 3


Once you enable OG Context, that comes with Organic Groups module, you can clone the og_members view since it does almost what you want: it shows members from one group.

The OG Context module allows the "OG membership: Group gid" contextual filter to have a default value set to "Current OG Group from context". Nice, but we need members from all of the current use groups. So change the default value to "User ID from logged in user" to pass in the current user as the default argument. Then check the "Specify validation criteria" checkbox and choose PHP Code.

// let's see if there is a logged in user
if ($argument) {
  // og_get_entity_groups() returns the logged in user groups
  $groups = og_get_entity_groups();
  // setting $handler->argument changes the argument value 
  $handler->argument = implode('+', $groups);
  // you have to return TRUE, else nothing works
  return TRUE;
// this will run if $argument is 0, for anonymous users
else return FALSE;

The "Action to take if filter value does not validate" should be "hide view": no block is shown if there is no logged in user. Expanding the "More" fieldset should be a "Allow multiple values" checkbox. Check it: that's why we imploded the groups array in the argument validation — this way we can pass several groups as arguments.

  • I noticed this might print duplicate members, even if you set the Query Settings: Distinct. Commented Jan 14, 2012 at 3:36

You can use the URL, but you have to tell the block to do so. 1. Create a contextual filter and go to the section When the filter value is NOT available, and select Provide Default Value checkbox. 2. For Type, select Provide raw value from URL 3. Tell the filter which segment of the path you wish it to use.

I have not tried views with OG, but if you set your format to filters, you can expose any fields associated with the view. If you do not see what you are looking for in the list, use the relationships form in the Advanced section of the view form to access the fields you need. (You may need to ask anther question when you get into relationships.)

  • Regarding the use of a URL - it doesn't really get me anywhere, because I'm using this as a block on (a lot of) nodes that have nothing to do with the OG. I'll try experimenting more with fields and seeing what can be exposed, but really what I'm trying to do is just show a list of users in the same OG.
    – Doug Estey
    Commented Nov 14, 2011 at 16:48
  • Basically, I'm trying to do this. imgur.com/BcyCf Except provide the group ID automatically via the logged in user - not through a URL argument.
    – Doug Estey
    Commented Nov 14, 2011 at 18:01

If you add a relationship n the advanced column and select Content:Author, you can then add a field (column 1) for the User ID (UID).

With the UID exposed, check back in relationships to see if the Group is now accessible. (Sorry, I am not certain how OG handles this info so I can not answer specifically here).

Please, let me know if this works.

  • I can't add Content:Author because this is not a content view, it is a user view. I'm trying to show users. Group is always available to add as a relationship and I've been experimenting with it already as shown in my screenshot.
    – Doug Estey
    Commented Nov 14, 2011 at 20:55
  • I guess I can't read! :) I've not used OG so .... but I am interested in if you find an answer. Please post if you can connect it.
    – Ashlar
    Commented Nov 15, 2011 at 2:34

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.