I would like to get a value from the reference node of the node_id I used this code for PHP code in Contextual filter...

$node = menu_get_object();
if ($node->type == 'trailer_videos'){    
       $mynode = node_load($node->nid)->field_trailer_video_of[und][0][target_id];
return $mynode;

The result is CORRECT!! but the page itself throw 2 errors:

  • Notice: Use of undefined constant und - assumed 'und' in eval()
  • Notice: Use of undefined constant target_id - assumed 'target_id' in eval()

Whats wrong with my code above????

  • you need quotes around 'und' and 'target_id'.
    – Ollie
    Commented May 2, 2015 at 16:51
  • Welcome to Drupal Answers! That is a simple PHP notice caused from code that doesn't follow the correct PHP syntax. We suppose you know PHP syntax; we cannot teach it here, since PHP syntax doesn't change using Drupal instead of WordPress.
    – apaderno
    Commented May 2, 2015 at 19:33

1 Answer 1


Why don't you use entity metadata wrapper? your code will be:

$node = menu_get_object();
    if ($node->type == 'trailer_videos'){
           $wrapper = entity_matadata_wrapper('node',$node);
           $mynode = $wrapper->field_trailer_video_of->value();
           return $my_node;

If you don't want to use entity module, use kpr of devel module to get the right syntax, as Ollie said quotes are needed.

  • This is a good suggestion. I am not sure somebody who doesn't understand a PHP notice will grasp it, but I definitively support this suggestion.
    – apaderno
    Commented May 2, 2015 at 19:42
  • @kiamlaluno may be you are right, First they should start building web applications without any CMS or framework. Using these tools must be the last step of their way to web programming
    – M a m a D
    Commented May 2, 2015 at 21:14

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