-
-
Save quevon24/005020b2eb8e746f6477750d4ef8b043 to your computer and use it in GitHub Desktop.
Load field without Node_load
This file contains 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