diff --git a/og_forum.module b/og_forum.module
old mode 100644
new mode 100755
index 4e37b94..b334899
--- a/og_forum.module
+++ b/og_forum.module
@@ -88,8 +88,12 @@ function og_forum_query_term_access_alter(QueryAlterableInterface $query) {
   // Load all the groups of the user for which the query is executed.
   $group_gids = array();
   $groups = og_get_entity_groups('user', $account);
-  foreach ($groups as $gid => $value) {
-    $group_gids[] = $gid;
+  // Changed in og 7.x-2.x, the group array is in the format of
+  // array($group_type => array($membership_id => $entity_id)).
+  foreach ($user_groups as $group_type => $groups) {
+    foreach ($groups as $gid) {
+      $group_gids[] = $gid;
+    }
   }
 
   // Find all instances of the {taxonomy_term_data} table being joined --
@@ -97,17 +101,14 @@ function og_forum_query_term_access_alter(QueryAlterableInterface $query) {
   // Join each one to the OG Group audience table.
   $tables = $query->getTables();
   foreach ($tables as $talias => $tableinfo) {
-
     $table = $tableinfo['table'];
     if (!($table instanceof SelectQueryInterface) && $table == 'taxonomy_term_data') {
-
       $audience_alias = $query->leftJoin('og_membership', 'ga', '%alias.etid = ' . $talias . '.tid
-                                          AND %alias.entity_type = :entity_type
-                                          AND %alias.field_name = :field_name',
-                                        array(
-                                          ':entity_type' => 'taxonomy_term',
-                                          ':field_name' => 'og_group_access',
-                                        ));
+      AND %alias.entity_type = :entity_type
+      AND %alias.field_name = :field_name', array(
+        ':entity_type' => 'taxonomy_term',
+        ':field_name' => 'og_group_access',
+      ));
       $condition = db_or();
       $condition->isNull($audience_alias . '.gid');
 
@@ -249,7 +250,7 @@ function og_forum_og_role_grant($gid, $uid, $rid) {
     $query = new SelectQuery('og_membership', 'om');
     $query->innerJoin('taxonomy_term_data', 'td', '%alias.tid = om.etid');
     $query->innerJoin('taxonomy_vocabulary', 'tv', '%alias.vid = td.vid
-                      AND %alias.machine_name = :forums', 
+                      AND %alias.machine_name = :forums',
                     array(
                       ':forums' => 'forums'
                     ));
@@ -280,7 +281,7 @@ function og_forum_og_role_revoke($gid, $uid, $rid) {
     $query = new SelectQuery('og_membership', 'om');
     $query->innerJoin('taxonomy_term_data', 'td', '%alias.tid = om.etid');
     $query->innerJoin('taxonomy_vocabulary', 'tv', '%alias.vid = td.vid
-                      AND %alias.machine_name = :forums', 
+                      AND %alias.machine_name = :forums',
                     array(
                       ':forums' => 'forums'
                     ));
@@ -459,7 +460,7 @@ function og_forum_get_roles_by_permission($group_type, $bundle, $gid, $permissio
  *   Array with the user IDs.
  */
 function og_forum_get_users_by_roles($gid, $rids = array()) {
-  if (empty($rids)) { 
+  if (empty($rids)) {
     return array();
   }
 
