0

Currently I am using a query to load field collections of a specified type, but I wonder if there is a more drupaly way to do it?

$query = db_select('field_collection_item', 'fci')
  ->fields('fci', array('field_name', 'item_id'))
  ->condition('fci.field_name', $field_collection_name)
;

$result = $query->execute()->fetchAllAssoc('item_id');
$fcs = entity_load('field_collection_item', array_keys($result));

1 Answer 1

0

Lets say you have field collection with type 'field_my_dates'. So you can get field collection details using node and collection type as given below.

<?PHP
    $itemCollection = field_get_items('node', $node, 'field_my_dates');
    $wrapper = entity_metadata_wrapper('node', $node);
?>

Thanks

1
  • Am I correct in thinking this would load field collections of only a single node? That's not what I want -- I want to get all field collections of a particular type.
    – user1359
    May 6, 2015 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.