Skip to content

Instantly share code, notes, and snippets.

@josmera01
Last active November 17, 2017 20:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save josmera01/18a2995018960c5d0bdb to your computer and use it in GitHub Desktop.
Save josmera01/18a2995018960c5d0bdb to your computer and use it in GitHub Desktop.
Load field without Node_load
<?php
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('field_image', 'fid', 'NULL', '!=')
->range(0, 1);
$result = $query->execute();
if (isset($result['node'])) {
$stories = $result['node'];
$stories = reset($stories);
dpm($stories);
// At first we need to get field's id. If you already know field id, you can ommit this step
// Get all fields attached to a given node type
$fields = field_info_instances('node', 'article');
// Get id of body field
$field_id = $fields['field_image']['field_id'];
// Attach a field of selected id only to get value for it
field_attach_load('node', array($stories->nid => $stories), FIELD_LOAD_CURRENT, array('field_id' => $field_id));
dpm($stories);
// Get values of our node field
//This function is options
$output = field_get_items('node', $stories, 'field_image');
dpm($output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment