i have writed this code to unset empty terms :
function shs_selective_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_form' && $form['#id'] == 'views-exposed-form-projet-immobilier-page-1') {
foreach ($form['field_r_t_tid']['#options'] as $tid => $term_name) {
if (is_numeric($tid)) {
$result_count = db_select('taxonomy_index', 'ti')
->fields('ti')
->condition('ti.tid', $tid, '=')
->execute()
->rowCount();
// Removing the option for tags with no-content
if (!$result_count) {
unset($form['field_r_t_tid']['#options'][$tid]);
}
}
}
}
}
but is not worked, he show me this error : Undefined index : #options ... how can i resolve this error?