The location field consists of multiple fields, like Street, City, Region, Postcode, Country etc.

In my AutoNodeTitles I'm using PHP to print render 2 elements: Street and City from the Location field. But whatever I do in D7 it doesn't seem to work. In D6 I had this:

return $node->field_location[0]['street'] . ', ' . $node->field_location[0]['city'];

which would return to me something like: "31 Liverpool Street, London", for example.
But in D7 I can't fetch 'street' and 'city', whatever I do.

<?php print render($content['field_location'][0]); 

?> will render all values of that whole field (including postcode and "See map: Google Maps", which is very ugly and unprofesssional for a title, but I need only Street and City)

<?php print render($content['field_location'][0]['street']); ?> doesn't return anything. Maybe I'm just not treating arrays and keys with correct spelling... (I'm not much of a coder)

It seems like a no-brainer, but doesn't seem to work. Would you be kind enough to help with this little PHP snippet?

Much obliged.


druvision’s picture

Print the node array with dsm($node) - (you should have devel installed).
Then you will see the exact contents of the array.
You've probably missed the lang attribute - for regular non-location fields it's $node->field_location[$node->language][0]['value'];