Load correct field collection revision from template.php

Public

If revisions is being used with field collections there may be a chance you'll always load the latest live field collection, rather than the one assisted with the revision being viewed. If you're using field collections within template.php you'll need the below snippet to load the correct fc to the node revision being viewed.

</> CopyGet raw version
php
  1. // Get the field collection field.
  2. $field = field_get_items('node', $node, 'field_field_name', $node->language);
  3.  
  4. foreach ($field as $f) {
  5.  
  6. // Load the field collection.
  7. $d = field_collection_field_get_entity($f);
  8.  
  9. // Do what you want with the field collection here.
  10.  
  11. }