I have more than 10 terms in vocabulary: car, red car, blue car, yellow car etc. I know that 10 results is hardcoded value for autocomplete widget. My problem is that after typing "car", I only get various other terms, simple "car" is not in suggestions.

How does the autocomplete widget work? Is there any way how to sort/alter results? Why it does not show the exact term first "car" and then all other terms containing "car"?

1 Answer 1


The filter handler class views_handler_filter_term_node_tid uses the autocomplete path admin/views/ajax/autocomplete/taxonomy and is driven by the callback views_ajax_autocomplete_taxonomy().

This autocomplete callback explicitly excludes the term typed in and doesn't do any explicit sorting (thus defaults to whatever your RDBMS does):

$query = db_select('taxonomy_term_data', 't');

// Do not select already entered terms.
if (!empty($tags_typed)) {
  $query->condition('t.name', $tags_typed, 'NOT IN');
// Select rows that match by term name.
$tags_return = $query
->fields('t', array('tid', 'name'))
  ->condition('t.vid', $vid)
  ->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
  ->range(0, 10)

If you'd like to alter the results or how it's sorted, the query is using tagging, thus available for altering via hook_query_alter().

  • HI, thank you for explanation. It is weird that the query explicitly excludes the term typed, though.
    – loparr
    Commented Jul 31, 2016 at 14:39
  • The field accepts comma delimited list of fields. I think the design is meant not to suggest a terms already entered after a user types it out.
    – Shawn Conn
    Commented Jul 31, 2016 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.