Q:

Remove child elements from Taxonomy List Exposed Filters

I have a view with (Taxonomy Reference Field) as Exposed Filter, The vocabulary contain parent terms and some child terms, I want to see the first level terms only and remove any children if any. 
Currently It look like this

I want to remove the Keyboard Type 1, Type 2 and so on. 
I was thinking of using a hook_form_alter, but not sure about the exact usage to remove any child term.

A:

Here is my solution which I think is quite a bit simpler. Simply remove the entries from the form if they start with a '-'. Note that you must have the 'Show hierarchy in dropdown' option selected for the children to begin with a '-' hyphen.
/**
* Implements hook_form_alter().
*/
function mymodule_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {

  if($form['#id'] == 'views-exposed-form-[your-view-here]') {

    foreach ($form['tid']['#options'] as $term_key => $term) {

      // Check if this isn't the 'ANY' option
      if($term_key !== 'All') {
        // Check if this is a child by looking for '-' as first char in string
        $term_value = reset($term->option);
        if($term_value[0] == '-') {
          unset($form['tid']['#options'][$term_key]);
        }
      }

    }

  }

}

