I am trying to define a custom field in D7 view, and I used views_php. Here few variables are available as field tokens, but while using it inside the code, it doesn't return its original value, but does the node id.

Available variables:

  • $view: The view object.
  • $handler: The handler object.
  • $static: A variable that can be used to store reusable data per row.
  • $row: Contains the retrieved record from the database (e.g. $data->nid).
  • $row->nid: Content: Nid
  • $row->field_twitter_page: Content: Twitter Page
  • $row->field_facebook_page: Content: Facebook Page
  • $row->php: Global: PHP
  • $data: Contains the retrieved record from the database (e.g. $data->nid).
  • $value: Value of this field.

I need to fetch the value of "$row->field_facebook_page"; so I wrote:

<a href="<?php print $row->field_facebook_page; ?>"Like</a>

When I click on the "Like" link, the given URL is empty. When I print the variable, I get the node ID.

What am I doing wrong?


2 Answers 2


Start with print_r to see what's available:

<?php print_r($data); ?>

You will likely end up using $data, something like:


If that doesn't work, take a look at http://drupal.org/node/1140896#comment-5945164


Thanks Keva. It works!

$node = node_load($row->nid); //loads the entire node values

$fburl = $node->field_facebook_page;

$twurl = $node->field_twitter_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.