<?php
// custom_exposed_year_filter.module
function custom_exposed_year_filter_form_views_exposed_form_alter(&$form, &$form_state) {
$field_id = 'field_reference_year_start';
// Only alter forms with the necessary field
if (isset($form[$field_id . '_value'])) {
// Build a query to get all node ids having the specified field
$query = new EntityFieldQuery();
$results = $query->entityCondition('entity_type', 'node')
->fieldCondition($field_id, 'value', 'NULL', '!=')
->fieldOrderBy($field_id, 'value', 'ASC')
->execute();
// Attach the field values to the nodes
$nodes = $results['node'];
field_attach_load('node', $nodes, FIELD_LOAD_CURRENT, array('field_id' => $field_id));
// Add a default so the filter is optional
$options = array('' => '<select>');
// Buld the options array based on the query results, overwriting duplicate entries
foreach ($nodes as $nid => $node) {
$value = $node->field_reference_year_start['und'][0]['value'];>{"$field_id"}['und'][0]['value'];
$options[$value] = $value;
}
// Alter the field
$form[$field_id . '_value']['#type'] = 'select';
$form[$field_id . '_value']['#options'] = $options;
$form[$field_id . '_value']['#size'] = 1;
}
}
Lastly, adjust the following linesline so they matchit matches the name of the field that you would like to filter for:
$field_id = 'field_your_field_name';
$value = $node->field_your_field_name['und'][0]['value'];