Posted By

depiction on 02/04/14



Versions (?)

Drupal: Get Custom Field value and default value

 / Published in: PHP

This has been tested in page.tpl.php. Get the custom field value. If the value is emtpy, get the default value. Be sure to replace the field and content type values.

Also see: and

  1. $phone = field_get_items('node', $node, 'field_phone_number');
  2. $phone = $phone[0]['safe_value'];
  3. if ($phone == NULL) {
  4. $field = field_info_field('field_phone_number');
  5. $instance = field_info_instance('node', 'field_phone_number', 'CONTENT_TYPE');
  6. $phone = field_get_default_value('node', $node, $field, $instance, $node->language);
  7. $phone = $phone[0][value];
  8. }

Report this snippet  

You need to login to post a comment.