Last active
December 14, 2015 06:19
-
-
Save sanguis/5041331 to your computer and use it in GitHub Desktop.
entityfieldquery for returnining distinct links to a taxonomy category for a term
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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