1

I am using the below code to get the value of email. It works fine if the field type is "Text". But the field type used is "Email"

<?php
  $node=node_load(14);
  print $node->field_contact_email[$node->language][0]['value'];
?>

Please help.

1 Answer 1

2

As it's an Email field, you need to query the array for email not value:

$node = node_load(14);
print $node->field_contact_email[$node->language][0]['email'];

// Outputs:
[email protected]

If you're intending on rendering the email address on a page, you should look into using field_view_value, which will give you a string of HTML markup for a field value. The benefit of this, is that it will use the rendering function for what ever field type you supply it with.

$node = node_load(14);
$email = field_get_items('node', $node, 'field_contact_email');
$output = field_view_value('node', $node, 'field_contact_email', $email[0]);
print $output['#markup'];

// Outputs:
<a href="mailto:[email protected]">[email protected]</a>
0

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.