111

I'm adding a contextual filter to a view for a custom content type that has a taxonomy field. The contextual filter allows me to filter by the taxonomy tag id but not by the taxonomy tag name. Meaning with the given tags in the taxonomy:

1  | test1
2  | another tag
3  | taggy
......
99 | coolness

I can generate a contextual filter that will parse a URL like http://mydrupal/myview/3 to display all content that has been tagged with taggy BUT, the URL needs to pass the argument to lookup by tag name instead of tag id, e.g., http://mydrupal/myview/taggy to view all content tagged with taggy How can this be accomplished?

2 Answers 2

161

I assume you've added the Content: Has taxonomy term ID contextual filter. You can use taxonomy term names with this filter by adjusting Specify validation criteria settings. here's a screenshot:

Screenshot

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.

6
  • 6
    in all honesty this isnt very intuitive for taxonomy terms. This answer helped me solve a week long problem. :) Commented Aug 17, 2011 at 20:49
  • brilliant! Thanks a lot for the detailed solution. I would have never figured that out on my own.
    – uwe
    Commented Aug 24, 2011 at 19:35
  • 1
    This was a big help. Thanks. However, It appears if you are passing multiple taxonomy terms separated by + signs, it doesn't not work. Or rather, I think it's using and And instead of an Or.
    – user2992
    Commented Sep 16, 2011 at 18:34
  • 2
    Worth noting -- if you've attempted to pass a term ID via a Panels View Pane context argument and then you try this, having the context argument set will cause the contextual filter to not supply the default. Again, that "context argument", which is different from "contextual filter" and its default value. Was rather confused for a few minutes...!
    – aendra
    Commented Jan 11, 2013 at 16:04
  • 1
    I have chosen all the options above, I want to show for example "animals/pets/cats" but it doesn't work, only works if I put "cat" in the "Preview with contextual filters" box , tried all combinations, animals+pets+cats, "animals,pets,cats", "animals-pets-cats", how can I do that? Commented Sep 14, 2017 at 12:26
8

Another way to skin the cat:

I needed the actual taxonomy term name query not converting to term ID.

Here is how to query the taxonomy term name that was passed as a contextual filter:

To get the name you must add a relationship, either on the field or the generic taxonomy relationship. Then you can add any fields for that term as a contextual filter, including the name.

https://www.drupal.org/node/1156022#comment-4469378

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