4

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

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

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.

  • 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 '17 at 17:13
1

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 '17 at 10:31
  • I wrote the complete solution, see new edits. – Mohammed Gomma Oct 20 '17 at 17:08
0

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.

  • 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 '17 at 4:47
  • 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 '17 at 5:29
  • 1
    I added to the original question to make it more clear. – Sam Oct 20 '17 at 10:31
0

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.

Regards.

[Edit]

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.

[/Edit]

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.