0

The taxonomy contains mostly 3 levels, sometimes two levels only.

Parent
  Child 1
    Grandchild 1
  Child 2

Via path alias, the patterns create URLs like:

/parent/child1/grandchild1
/parent/child2

When I configure my views block with the logic for the grandchild and place this blog into the layout builder of the taxonomy, it's working like a charm. enter image description here

Only when I hit the the URL of the child (not grandchild) I get the error:

Drupal\Core\Database\InvalidQueryException: Query condition 'taxonomy_term_field_data.name IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 117 of core/lib/Drupal/Core/Database/Query/Condition.php).

(which seems to make sense, since there is not 3rd component in my path - /parent/child2)

How to "catch" the request without a 3rd component or how can I validate either component 3 or 2 (and I'd need 1 as well in some cases).

4
  • The easiest way is just to have 2 blocks within your view. 1 looking for arg3 and 1 looking for arg 2 Commented Mar 20, 2023 at 13:26
  • That would be fine. Issue is just the error. How to make sure, if there is no arg3, then I'd only show results for arg2?
    – Chris
    Commented Mar 22, 2023 at 18:32
  • Settings for the contextual filter already give you that option. What did you choose below the Specify validation criteria? Do you have 2 Contextual filters, one for child, another for grandchild, in correct order, and with correct Relationships?
    – prkos
    Commented Mar 22, 2023 at 20:39
  • I couldn't get it working via the path. Now I'm using Content: Has taxonomy term ID as a contextual filter and it works directly for all depths and even with special characters.
    – Chris
    Commented Mar 24, 2023 at 5:12

0

Your Answer

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

Browse other questions tagged or ask your own question.