How to provide default value with PHP code for a field in Views 3 So I'm trying to create a View, displayed in a Block, that will show a list of nodes that reference the same parent node as the node I'm currently in. The reference is a custom field using the References module. I'm on Drupal 7 with Views 3.

I figure I'll setup a Contextual Filter on my custom field (field_ref_photo_gallery) and I need to provide a default value via PHP code.

How should I write that PHP code in the most Drupal 7-ish way? 

Should I go with something like:

return node_load($nid)-&gt;field_ref_photo_gallery['und'][0]['value'];


(I'm not even sure that would work. I just threw that together in this post)

Or is there a field API function I should be calling?
You can pass currently viewing nodes id in contextual filter without using any custom code.

In contextual filter settings, under When the filter value is NOT in the URL select Provide default value option. Then there is a dropdown will show. Then select Content ID from URL. See the image: