Displaying Organic Group members based on a Views Contextual Filter The end goal here is to get a list of organic group members based on a contextual filter.

The path for the view is groups/%/members, where the contextual filter is "OG membership: Group ID" and defaulted to custom PHP code. (Because the "Current OG from Context" wouldn't work.) 

The custom PHP code is as follows (based off of this solution on d.o):

 if(arg(0) == 'groups' &amp;&amp; arg(1) != null){
  $node_path = drupal_get_normal_path('groups/'.arg(1));

  $node_id = substr($node_path, 5);

  // Check if node referenced by arg(1) is a group
  if(og_is_group('node', $node_id)){
    return $node_id;
  }
  else {
    return null;
  }
}
else{
  return null;
}


There is a relationship to OG membership: OG membership from User there also. It makes no difference if the contextual filter is referencing the relationship or not. 

If I "Preview with contextual filters" in the Views UI with a group's NID, the view works. So I know it's just the default value of the contextual filter.

I have something very similar in the "No Results Found" section for troubleshooting purposes, the only differences is it outputs some additional strings to clarifiy where the returns are firing. When I save the view and go look at the page, it returns "No results found" but also returns the correct NID/GID from the PHP. My suspicion is that the PHP code isn't validating with views for some reason.

The view needs to be a page, so I can't use the default block view provided by the OG module. ("OG members (user)")

The only thing I am set on is a working solution, so if you have a suggestion on doing it differently, I am open to other ideas. 

Contextual filters I have tried that do not work are:
-Content ID from URL 
-OG Group from context
-Raw value from URL

Any help or point in the right direction would be greatly appreciated.

Thanks!
Okay so the problem turned out I was returning the wrong variable. 

I needed to return $handler->argument instead of whatever variable I was using. 

So my function I put in my contextual filter was:

if(arg(0) == 'groups' &amp;&amp; arg(1) != null){
  $node_path = drupal_get_normal_path('groups/'.arg(1));

  $node_id = substr($node_path, 5);

  // Check if node referenced by arg(1) is a group
  if(og_is_group('node', $node_id)){
   // return $node_id;
   $handler-&gt;argument = $node_id;
   $node = node_load($node_id);
   $handler-&gt;validated_title = $node-&gt;title;
   return $handler-&gt;argument;
  }
  else {
    return null;
  }
}
else{
  return null;
}


(I cleaned up the code a little and adjusted it to strip out the unnecessary stuff.)