Redirect User to OG group page after login

Public

Thanks to User Nonprofit on drupal.org
Reference from http://groups.drupal.org/node/213088#comment-703153

</> CopyGet raw version
php
  1. // Add a rule with
  2. //Events: User has logged in
  3.  
  4. // add users to role and groups both
  5. //Conditions: User has role(s)
  6.  
  7. //Actions:
  8. //Execute custom PHP code:
  9. global $user;
  10. $uid = $user->uid;
  11. $result = db_query ( "SELECT * FROM {og_membership}
  12. WHERE etid = :uid
  13. and entity_type = 'user'
  14. order by gid DESC", array (':uid' => $uid ) );
  15. // get the results
  16. foreach ( $result as $row ) {
  17. // Do stuff with $record, which is an object
  18. $gid = $row->gid;
  19. break; //get the latest one by breaking here
  20. }
  21. $_SESSION['ses_user_group_gid'] = $gid;
  22.  
  23. //Page redirect:
  24. <?php print "partners/".$_SESSION['ses_user_group_gid']; ?>