I'm using Drupal 7, and trying to work some magic from within a hook_node_presave() function.

I have a node reference field, and I'm trying to get the name of the referenced node rather than nid. When I trace out the field ($node->field_my_name) I get the following

    [und] => Array
            [0] => Array
                    [nid] => 23



I wondering if there is a way to get the title without doing a full load of the referenced node. Is there anyway I can do this with a token? Would this no be an issue if I were using entity reference rather than references?

  • 1
    more than likely, the node is cached anyway and node_load(23) won't too adversely effect performance. Jan 13, 2012 at 18:08
  • good point, I'm just really surprised that there is no function to load the title of a node, give the nid, I just tried to do it with a static query, but for some reason it didn't work
    – user379468
    Jan 13, 2012 at 18:39

1 Answer 1


You could use entity_label() function.

The function takes the entire entity as an argument, and it should already be loaded.
I would just load the node. As the other author suggested, it is very likely to be already cached in a hook_node_presave() call.


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.