For D6 the solution is posted here: http://drupal.org/node/879404

To count the number of values in a cck multi value field. In my case the number of images in a multi-value image field. When using the Computed Field module, put this code in the Computed Code field:

if (is_null($node->field_images[0]['fid']))
{
$node_field[0]['value'] = 0;
}
else
{
$node_field[0]['value'] = count($node->field_images);
}

Put this in the Display Format field:

$display = $node_field_item['value'];

But how do I achieve this for D7?
It would be great to add this to the handbook here: http://drupal.org/node/249907#comment-5719508

Comments

Rhodungeon’s picture

I have the same issue... How can I exclude empty values from the count in Drupal 7?

I've entered this code

$entity_field[0]['value'] = count(field_get_items($entity_type, $entity, 'field_sostanze_con_stesso_noael'));

But it gives me value "1" even if the field is empty.
I can't find a solution working for Drupal 7.
I would appreciate a little help.

Thanks!

apoc1’s picture

I know this is old, but I have the same problem. What are we doing wrong here?