What is the correct method of getting term name in the page title field if I have passed the term id in contextual filter. I have added the Content: Has taxonomy term ID contextual filter in views, I have tried to overwrite the page title be provide "%1" but that also provides term id as the "filter value type" contains term ID.

One way to achieve this using the "global php" field in the header and getting the term ID from the argument as "arg(1)", and getting the term name from the term ID and than setting page title using "drupal_set_title($term_name)".

enter image description here

enter image description here

  • How did you give the override option? It works fine that way.. – Mohammed Shameem Sep 30 '13 at 14:47
  • Thanks for reply, but I have tried that by providing "%1" in override title link, and it is than displaying the term id but I require the term name. – Ankit Agrawal Sep 30 '13 at 14:54
  • could you take a screenshot of the views config screen and post it in the question. – Mohammed Shameem Sep 30 '13 at 14:59
  • @MohammedShameem Added :) – Ankit Agrawal Sep 30 '13 at 15:57
  • you should try removing the % from the path and make the path just product-category – Mohammed Shameem Sep 30 '13 at 16:02

Answers Updated: try this hook, hook_view_pre_render()

This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.

function MYMODULE_views_pre_render(&$view) {
  if ($view->name == 'your_view_name') {
     $term = taxonomy_term_load(arg('arg_position_in_url'));
     $title = $term->name;
     $view->build_info['title'] = $title;
| improve this answer | |
  • Thanks Arpit, I have mentioned this solution in the question. This is definitely one of the possible solution, but I am trying to see If we can have some better solution. – Ankit Agrawal Sep 30 '13 at 16:50
  • check with updated answer – arpitr Sep 30 '13 at 17:04
  • @ankit please did that work for you? or you got better way to do this, please share if so – arpitr Oct 1 '13 at 7:44
  • I am waiting to see if we can some better alternative, otherwise this is definitely one to go with. – Ankit Agrawal Oct 1 '13 at 7:57

Got the solution:

The mistake I was doing was selecting the "Display all results for the specified field" for the "When the filter value is NOT in the URL" field of contextual filter, Instead I was supposed to do the following for this field:

  • Check "Provide default value".
  • Select Type: "Taxonomy term ID from URL"
  • Select checkbox: "Load default filter from term page"

and rest everything as mentioned in the question.

enter image description here

| improve this answer | |

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.