Always we have to face a hard works to get field collection data in views, node_load, etc. I am giving a example code in below for load field collection fields data in a entity.
entity is “Node”,
Field collection field is “field_timeline”
[sourcecode language=”bash”] $timelineData = entity_load(‘node’, array($node->nid) );
$node_data = $timelineData[ $node->nid ];
$wrapper = entity_metadata_wrapper(‘node’, $node_data);
$timelineCollection = field_get_items(‘node’, $node_data, ‘field_timeline’);
$date_points = array();
if( $timelineCollection ) {
foreach( $timelineCollection as $delta => $collection ) {
$date = $wrapper->field_timeline[ $delta ]->field_timeline_date->value();
// dsm( $wrapper->field_timeline[ $delta ]->field_timeline_image->value() );
$temp = array();
$temp[‘startDate’] = date(‘Y,m,d’, $date );
$temp[‘endDate’] = date(‘Y,m,d’, $date );
$temp[‘headline’] = $wrapper->field_timeline[ $delta ]->field_timeline_title->value();
$temp[‘text’] = $wrapper->field_timeline[ $delta ]->field_timeline_image->value();
array_push( $date_points, $temp);
[/sourcecode] Thanks

1 Comment

  • funky 2D
    July 23, 2014

    Hi thanks for the explanation,
    I’m trying to do something similar but i’m stuck with an error on “$node->nid”.
    What do the $node contain ?
    Thanks in advance


Leave a Reply