If you want to list Organic Group content in a View you must do a little more that just add one reference.
The default example is available if you enable Organic Groups. The name of that View is "OG content" (machine-name: og_nodes).
I put it here on the blog because our usecase didn't use Organic Groups' default reference field (og_ref that is) and because we chained multiple groups (a group has content and a group is part of a parentgroup).
2 og-reference-fields, 3 content-types
In our case we used 2 different og-reference fields and 3 content-types were involved:
- Parent Group Content-type: country.
- Normal Group Content-type: team. OG-field: field_og_country.
- Content Content-type: news. OG-field: field_og_team.
Now with a View we want to get News-content from all Teams part of a Country.
With a normal entity reference field (not OG) you need 2 relations, in our case (yes OG) we need 4.
Add relationships to your View
Create your View, now add these 4 relations in this exact order:
1. "OG membership: OG membership from Node" [The OG membership associated with the Node entity.]
- (This is the Team-group where the News-item is posted in)
- Enable 'Require this relationship' to speed up the query.
- As identifier and Administrive title put "OG membership from Node Team" to improve your maintainability.
2. "OG membership: Group Node from OG membership" [The Node group that is associated with the OG membership.]
- As Relationship use the relation created in step 1. (critical)
- Enable 'Require this relationship' to speed up the query.
- As identifier and Administrive title put "Group node from OG membership Team" to improve your maintainability.
3. "OG membership: OG membership from Node" [The OG membership associated with the Node entity.]
- (This is the Country-group where the Team-item is posted in)
- As Relationship use the relation created in step 2. (critical)
- Enable 'Require this relationship' to speed up the query.
- As identifier and Administrive title put "OG membership from Node Country" to improve your maintainability.
4. "OG membership: Group Node from OG membership" [The Node group that is associated with the OG membership.]
- As Relationship use the relation created in step 3. (critical)
- Enable 'Require this relationship' to speed up the query.
- As identifier and Administrive title put "Group node from OG membership Country" to improve your maintainability.
Add a contextual filter to your View
As last step you can create the Contextual Filter that is used to filter on the ParentGroup (Node-ID from Country).
5. "Content: Nid" [The node ID.]
- As Relationship use the relation created in step 4 = "Group node from OG membership Country". (critical)
- And if you like: 'Provide default value': Content ID from URL.
Check your results
When you render this View on a Country-node, all News articles from Teams that are linked to the Country are listed.