I want to display a block on each page (nodes as well as pages created by Views) that displays links to nodes that are tagged with a certain taxonomy term.

How to decide which tag should be used:

  • {1} If the page is a node that references a taxonomy term:
    use the referenced term
  • {2} If the page is a node that doesn’t reference a taxonomy term (= empty value):
    use the term with ID 1
  • {3} If the page is not a node (= created by Views):
    use the term with ID 1

I managed to get the links shown in case {1}, by using the relationship "Content: Taxonomy terms on node" and the contextual filter "Taxonomy term: Term ID" which uses the relationship.

I selected "Provide a default value" (Type: "Taxonomy term ID from URL" + "Load default filter from node page, that’s good for related taxonomy blocks"). So I can’t specify the default value here for case {2} and {3}.

Then I thought I could use the validation options somehow, but "Action to take if filter value does not validate" does not allow me to set a specific value in case the original default value does not exist.

How could I solve this?

tl;dr: I need something like: Take term ID from URL (via node ID), and if this gives no term ID, use term ID 1 instead.

1 Answer 1


Just set your contextual filter to return 1 when the value is not available like so:

Drupal Answer

  • But I already used this field for case {1}, to provide the term ID as default value.
    – unor
    Mar 30, 2016 at 18:06
  • I think your only solution is to use Php code on the contextual filters then. Check if it's a node, then use node_load(), check taxonomy term and return it, if it's not a node return 1
    – guibfo
    Mar 30, 2016 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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