1

when i created view it shows the result and and the query in a preview and here is the query

SELECT node.title AS node_title, node.nid AS nid, node.language AS node_language, 
node.created AS node_created, 'node' AS field_data_field_image_node_entity_type, 'node' AS field_data_body_node_entity_type
FROM 
{node} node
WHERE (( (node.language IN  ('en')) AND (node.type IN  ('news')) ))
ORDER BY node_created DESC
LIMIT 2 OFFSET 0

there is a field that hold the image value i think (field_data_field_image_node_entity_type) but when i loop the result it does not display image value inspite it displayed in view result preview how am i get this value of image to display it rather than using views

2

Views doesn't directly query every piece of that it needs to render data.

Some of the data is build on the pre_render hook.

The pre_render hook runs after the initial view query and is used to generate some of the missing data.

In drupal 7 views uses a pre_render hook for loading the fields via a entity_load and then field_get_items.

This is also common in the drupal 6 version of view. One good example is the Taxonomy get All terms. This is also build on the pre_render hook.

If you want to get this field without using view you can do this

$entity = entity_load('node', $nid);
$image_field = field_get_items('node', $entity, 'name_of_the_field');

The field you want is now in the $image_field variable.

1

Most likely views is doing an entity load, to get the node and all of it's fields. You could do the same, for nodes you can do node_load($nid).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.