I'm new to Drupal, and I have some problems.
I need to select some fields from a node (via code), and then process the data.

content type fields

[Full-size image]

Basically, I want to show the total of column "value", grouped by "category", but as each field's content type is a table, I do not know how to do it.


To get the data from a field in an entity be it a node or something else is pretty straight forward.

It can usually be done doing something like this.

$data = $node->field_name['und'][0]['value']

But it depends on which field type you are using ect. A more convenient way is to use the entity module. With that installed you can do:

$node_wrapper = entity_metadata_wrapper('node', $node);
$data = $node_wrapper->field_name->value();

This giv give you the value, for reference fields like term reference, you will get the actual loaded term instead of the raw id which is pretty handy and allows chaining.

| improve this answer | |
  • Should be: $node->field_name['und'][0]['value'] :) – Berdir Jun 1 '11 at 21:55
  • @Berdir Good catch. Can you tell I'm fond of the entity module? – googletorp Jun 1 '11 at 22:12

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.