Skip to content

Instantly share code, notes, and snippets.

@sanguis
Last active December 14, 2015 06:19
Show Gist options
  • Save sanguis/5041331 to your computer and use it in GitHub Desktop.
Save sanguis/5041331 to your computer and use it in GitHub Desktop.
entityfieldquery for returnining distinct links to a taxonomy category for a term
<?php
$query = new SysbioEntityFieldQuery();
$query
->entityCondition('bundle', 'event')
->fieldCondition('field_event_type', 'tid', 'NULL', '!=')
->addTag('distinct')
;
$result = $query->execute();
$nids = $result['node'];
$fields = field_info_instances('node', 'event');
$field_id = $fields['field_event_type']['field_id'];
field_attach_load('node', $nids, FIELD_LOAD_CURRENT, array('field_id' => $field_id));
foreach($nids as $n) {
$item = field_get_items('node', $n, 'field_event_type');
$link = field_view_value('node', $n, 'field_event_type', $item[0]);
$link['#options']['attributes']['class'][] = 'block-event-listing';
$output[] = $link;
}
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment