8

I'm on d7. Im trying to figure out how to display all the nodes that are in an organic group. I feel like this is a major thing that the OG module should do and don't know why I cant figure it out. I have views installed and have looked at the OG content view, but it doesn't display anything when I test it with the preview filter. Ive seen a video on how to do this with panels, but I don't have panels installed and don't plan on it. Thanks for the help.

1 Answer 1

17

Here's how you can do it with views in Drupal 7. Create a new view of nodes as you normally would, but make sure you set up the appropriate relationship for it that will allow you to filter your nodes based on their group membership:

  1. Add a relationship (under the 'Advanced' section of the view)
  2. Select the 'OG membership: OG membership from Node' field, which is under the 'OG membership' section of the fields enter image description here
  3. Mark this as a required relationship on the next screen if you don't want to include nodes/content that do not have a group
  4. Only after you've added that relationship will you be able to see the appropriate 'Group id' filter. Go ahead and add a 'Contextual filter', also under the 'Advanced' section and select 'OG membership: Group ID'. enter image description here
  5. This filter will now allow you to input the Group Id as a filter to the view through the URL (test it with www.[your site].com/[your view path]/[group id]) or by figuring out which group you're currently in if you set the following screen properly for the contextual filter List item
  6. You can now test this in the view preview pane by entering in different OG id's and seeing that it should filter the list of nodes to ones only with those Groups set as their audience.

Let us know if this worked for you!!

2
  • Works fine, except for step 5, which is needed to make it work on group content pages. I believe this is due to Drupal issue #1781386, which see for workarounds.
    – tanius
    Commented Oct 10, 2014 at 18:28
  • 1
    This is good. Note that for D7 if you want to show content of only the groups that that currently logged in user belongs to you need to choose 'The OG groups of the logged in user' in the Type drop down in step 5 above. Commented Jun 22, 2015 at 10:07

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