I'm using Views exposed filters (dropdown) based on Term Reference (taxonomy Fields.)

It works but the query string it generates uses the Term ID (TID) instead of using the more readable and clean term name.

How do I change the query string to use the term name instead of TID? For example:

Current: http://test.com/test?gender=1

Desired: http://test.com/test?gender=female

  • 1
    Did you try the solution from this post I think it is similar.
    – guilhom
    Oct 20, 2017 at 13:10

5 Answers 5


You can use taxonomy term names with this filter by adjusting Specify validation criteria settings. here's a screenshot:

Content: Has taxonomy term ID contextual filter

Make sure Specify validation criteria is checked and you should be presented with more options. Under Validator choose Taxonomy term. You can optionally select with vocabularies to allow. Under Filter value type choose Term name converted to Term ID and check the Transform dashes in URL to spaces in term name filter values checkbox.

  • 1
    Your answer only applies to contextual filters (/value1/value2/value3) I am looking for answer that works for query string (?value=param&value2=parm)
    – Sam
    Oct 18, 2017 at 17:13

Two steps:

  1. Create a relationship between your base table and the 'taxonomy terms on node':

enter image description here

  1. Filter by Taxonomy term name:

enter image description here

The relationship allows the view to access parts of the taxonomy term other than the ID, such as its name.

  • 1
    Thanks @darvanen Taxonomy term: Name is available only as a search field, not a drop-down filter. I require a drop-down filter.
    – Sam
    Oct 20, 2017 at 4:47
  • 1
    In that case I think you'll need to write a custom module that alters the exposed form component as well. You should include that requirement in your question for anyone else who reads it =)
    – Darvanen
    Oct 20, 2017 at 5:29
  • 2
    I added to the original question to make it more clear.
    – Sam
    Oct 20, 2017 at 10:31

Use that module it will help views_contextual_filter_query

Allows url query values to be used as contextual filter arguments. This module is an answer to the many stackoverflow topics where the solution is to fetch query parameters by using the default PHP argument filter in Views (yucks!).

Use exposed form tpl to alter the select list to use term name as value

Configure validation criteria to use term name instead term Id.

The module will help you use contextual filters from query strings.

  • How will this change the query output of exposed filter?
    – Sam
    Oct 20, 2017 at 10:31
  • I wrote the complete solution, see new edits. Oct 20, 2017 at 17:08

AFIK, you will need to alter the way exposed filters lists the terms. If you inspect, you will see term ids as values. You will need to replace them with actual term names. You can use views API to do this. There is no other quick way to achieve this.



In addition to altering the term values in filter, you will also need to write the code that map the taxonomy names to term id when you perform an operation.



This is an ancient discussion, but still pertinent to Drupal 8 (and I presume 9).

I was able to solve it for my particular scenario with a minimal amount of code, only hooking into form_alter.

  1. Add a relationship to the view for the taxonomy term
  2. Add the taxonomy term name as a filter. This will make the URL argument work as expected, but the form field will be a text field instead of a select
  3. In the form_alter hook, change the text field to a select. Do a query to get all of the relevant taxonomy terms and add them as options.

Hacky, but relatively lightweight and no issues with functionality. Here's my form alter code, yours might look something like this.

function your_module_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
    case 'views-exposed-form-your-view':

      $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');

      $form['topic']['#type'] = 'select';
      $form['topic']['#attributes'] = []; // Optional, I had to remove a better exposed filters attribute that stopped auto submit
      $form['topic']['#options'] = [
        '' => t('All Topics')

      foreach ($term_storage->loadTree('topics') as $term) {
        $form['topic']['#options'][$term->name] = t($term->name);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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