Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quevon24/005020b2eb8e746f6477750d4ef8b043 to your computer and use it in GitHub Desktop.
Save quevon24/005020b2eb8e746f6477750d4ef8b043 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