I am trying to render out field collection content (event listings) from a drupal site and am having issues creating a loop that works properly. If a page, for example, has four event listings that were generated from fields (field_events_event_items) in drupal’s interface, I want to render out all four of those event. However I seem only to be able to render one.
I start by grabbing the array for events from the field they belong to…
<?php if ($node = menu_get_object()) { // Get the nid $nid = $node->nid; } $allEvents = field_get_items('node', $node, 'field_events_event_items'); ...and then (attempting) to loop through all of the event items... for ($i = 0; $i < count($allEvents); $i++) { $value = field_view_value('node', $node, 'field_events_event_items', $allEvents[$i]); $field_collection = $value['entity']['field_collection_item'][key($value['entity']['field_collection_item'])]; } If I print_r($allEvents) on a page with four events, I get an array that looks like I would expect it to: Array ( [0] => Array ( [value] => 2180 [revision_id] => 141356 ) [1] => Array ( [value] => 2181 [revision_id] => 141357 ) [2] => Array ( [value] => 2182 [revision_id] => 141358 ) [3] => Array ( [value] => 2183 [revision_id] => 141359 ) ) I would then think to print out the $field_collection variable to render out all four of the event, but when I do so I get only a single event generated. So what am I doing wrong? Yes, I suck. I will answer any questions provided. Thanks for the help.