Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
New to organic groups.
I've created a view of group content (nodes) to display on the user pages. The view shows content that the user (from the page argument user/n) has access to. I originally started by using "The OG Groups of the logged in user" for Groups Audience contextual filter, but I wanted something like "The OG Groups of the user object in the URL". So I changed for a custom query to return the gids.
if (arg(0) === 'user') {
$query = db_select('og_membership', 'ogm');
$query->condition('ogm.etid', arg(1), '=');
$query->condition('ogm.entity_type', 'user', '=');
$query->fields('ogm', array('gid'));
$results = $query->execute();
$arguments = '';
foreach($results as $result) {
$arguments .= $result->gid . '+';
}
return rtrim($arguments, "+");
}
Is there another way to do this without a custom query? Like using the OG relationships?
Cheers