I am trying to redirect the user to a page for which he is an organic user, and I want this redirect to happen after user login.

I am trying to use the hook_user_login() to make this redirect. However, I have found that when I inspect the $user object when it hits that hook, the $user->og_user_node field is empty. When I look at the user's edit screen (or when I inspect it with devel), it does have associated groups.

How can I retrieve a user's groups to make this redirect?


Since you are using code to do this you should be able to use og_get_groups_by_user to return that information. This will return all groups of either the active user or the $account object that you pass to the function.

You can also use Rules to do this without code pretty easily. There is a rule export on this page to help get started if you want to go that way.

Just to add: the place you are looking for the og group should be under og_membership I think, not og_user_nodes but that's off the top of my head :)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.