Drupal 6: getting particular fields from Node Reference types

drupaldrupal-6drupal-themingfield

I'm a drupal newbie…

<?php print $node->field_date[0]['view']; ?>

I can get the custom created CCK fields' value and display in tpl.php files as above… that's fine.

my question is how can I get the Node reference fields' in-fields? for example, I have an event content type, and I have defined Node Reference for Location (title, address, img, etc.). When I write the code below, it displays all location content;

<?php print $node->field_location[0]['view']; ?>

but I need to get only address field from this location content type. sth like below would be great 😀 but not working;

<?php print $node->field_location[0]['field_address']['view']; ?>

so how can get that? appreciate helps so much! thanks a lot!

Best Answer

You should inspect/dump the content of the $node->field_location array. I do not have a test installation at hand right now, so I can't say for sure, but I'd expect that at least the referenced nodes id ('nid') should be in that array somewhere. With that, you can do a node_load($nid), which returns the full node object, thus providing access to the fields.

(As said, I'm not sure, but the field array might already contain the whole node object as well, saving you from the need to load it explicitely.)

Related Topic