Is it possible to use node_load to get values from a node in a node reference field? I can't seem to get node_load to work, or I'm not use the object correctly?

$site = node_load($node->field_client_group_site[0]['nid']);
$node_field[0]['value'] = $site->field_id_number;

Comments

mshaver’s picture

Status: Active » Closed (fixed)

Figured it out. I needed the full node object path.

gjfreakout’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

Is it possible for anybody to explain me the above solution

robertjwhitney’s picture

yeah could you follow up on this? i think i have a similar problem.

jsommers’s picture

I hate when these things are left unfinished. This is exactly what I need. Anyone know what he means?

jsommers’s picture

This will work:

$artid = $node->field_ref_image_main[0]['nid']; //this is the field that is the reference to another node. This gets the node ID and sets it to a variable.
$mynoder = node_load($artid, NULL, TRUE); //this loads the node using the id from the reference field.
$node_field[0]['value'] = $mynoder->field_image_main[0]['value']; //this sets the output to whatever field you want to pull from the referenced node. For example. I wanted to get field_image_main from the referenced node.

This should work perfect. Let me know if you have questions. never posted code on here, hope the format is right.

fourmi4x’s picture

Thank you so much for this piece of code, exactly what I needed and it works perfectly!

colan’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Version 5 is no longer supported.