105

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?

156

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.

| improve this answer | |
  • 6
    in all honesty this isnt very intuitive for taxonomy terms. This answer helped me solve a week long problem. :) – PhiloSurfer Aug 17 '11 at 20:49
  • brilliant! Thanks a lot for the detailed solution. I would have never figured that out on my own. – uwe Aug 24 '11 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 Sep 16 '11 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...! – aendrew Jan 11 '13 at 16:04
  • @rocketeerbkw You have the AND/OR syntax backward! It kinda makes sense as you've written it, but it's not right. – doublejosh Oct 7 '16 at 23:48
6

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

| improve this answer | |

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