I have some more custom url with og group id like

  1. www.example.com/students/6593
  2. www.example.com/results/6953
  3. www.example.com/book-listing/5367/6953

    here 6953 is a group id.

these are the sample link. my questions is how to get the group id from url? And i can't use arg(). because i have more no of url and group id position also varied.

There is any robust solutions for this.

  • Is it going to be always the last part of the URL?
    – Djouuuuh
    Commented Nov 18, 2014 at 10:42
  • @Djouuuuh , Not, it would be in any place.
    – Leopathu
    Commented Nov 18, 2014 at 10:43
  • Is your group a custom content-type or taxonomy?
    – Djouuuuh
    Commented Nov 18, 2014 at 10:44
  • @Djouuuuh , Its a custom content type make it as group by the og module.
    – Leopathu
    Commented Nov 18, 2014 at 10:46
  • Where do you want to recover the group id? On a node page? On a View? What is the context?
    – Djouuuuh
    Commented Nov 18, 2014 at 10:50

1 Answer 1


I have used the following code in hook_preprocess_page() to solve this issue.

$url = current_path();
  $arguments = explode('/', $url);
  foreach ($arguments as $value) {
    if (is_numeric($value)) {
      $node = node_load($value);
      if (og_is_group('node', $node)) {
        drupal_set_message('group id :' . $node->nid);

From now, i can set to group member only could see this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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