Last active
November 17, 2017 20:21
-
-
Save josmera01/18a2995018960c5d0bdb to your computer and use it in GitHub Desktop.
Load field without Node_load
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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