Is it possible to have a custom filter for exposed criteria? When I've created a view where the filter criteria is:

"Content: Has taxonomy terms (with depth) (exposed)"


It works well, but I'd like to filter the terms. I have some "main term" and a lot of "sub-terms" for each "main term". What I'd like for this view, is to search only through "main term", i.e. propose in the list only "main term", not "sub-terms".

How can I achieve this?

If that may help: the parents of main "main term"s == 0 (in other words, "main term"s have no parents)
Here's the solution that works for me. I've been heavily inspired by this solution which is for Drupal 6, so I've adapted it for Drupal 7 and it works for me:

(Nota: I give two hints in the code : (1) how to make a query that asks for all nodes that have no parent (join on taxonomy_term_hierarchy where parent=0) and (2) how to search form terms using LIKE statement):

/**
 * Implements hook_form_alter().
 */
function bcg_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    if ($form['#form_id']=='views_exposed_form') {
        // override the original completion path which was:
        // 'admin/views/ajax/autocomplete/taxonomy/2'
        $form['term_node_tid_depth']['#autocomplete_path'] = 'admin/bcg/ajax/autocomplete/user';
    }
}

function bcg_menu() {
    $items = array();
    $items['admin/bcg/ajax/autocomplete/user'] = array(
        'page callback' =&gt; 'bcg_ajax_autocomplete_user',
        'access callback' =&gt; 'user_access',
        'access arguments' =&gt; array('access content'),
        'type' =&gt; MENU_CALLBACK,
    );
    return $items;
}

/**
 * bcg_ajax_autocomplete_user makes specific autocompletion
 */
function bcg_ajax_autocomplete_user($ajax_search = '') {
    $result = array();
    $vocabularies = taxonomy_get_vocabularies();
    foreach ($vocabularies as $obj) {
        if ($obj-&gt;name == 'MY_OWN_VOCABULARY') {
            $vid=$obj-&gt;vid;
            break;
        }
    }
    if (isset($vid)) {
        $results = db_query(
            'SELECT td.name ' .
            'FROM taxonomy_term_data td ' .
            'JOIN taxonomy_term_hierarchy th ' .
            'ON th.tid=td.tid ' .
            'AND th.parent=0 ' .
            'WHERE (' .
                ' td.name LIKE :name ' .
                'OR ' .
                ' td.description LIKE :name ) ' .
            'ORDER BY 1',
            array(
                ':name' =&gt; '%'.$string.'%'
            )
        )-&gt;fetchAll();
        foreach ($results as $obj) {
            $result[$obj-&gt;name] = $obj-&gt;name;
        }
    }
    drupal_json_output($result);
}