Get Users by roles for organic groups drupal7 I have following system roles  set up for users 


content publisher
content approver


All my users divided in to 5 organic groups.

I didn't set up any roles for organic groups.I am trying to get content approvers for particular group for approval process.

I tried using this function og_get_users_by_roles.

But the above function uses the organic group roles not system roles.

I am confused now should i setup same roles for organic groups.Please give some direction.
Try this if it works for you.call this function with user_role id and group id as parameter.

    function get_users_on_role_and_group_basis($rid, $gid) {
      $users = entity_load('user'); 
      foreach($users as $user) {
         if(is_array($user-&gt;og_user_node)) {
           if (array_key_exists($rid, $user-&gt;roles)) {
             foreach($user-&gt;og_user_node['und'] as $key=&gt;$values) {
               if(in_array($gid,$values)) {
                 $get_user[] = $user; 
                }
            }    
          }
        }        
      } if(isset($get_user)) {
          return $get_user;
        }else {
        return 0;
      }
    }