drupaldrupal-viewsdrupal-contextual-filters

Drupal 8, two contextual filters, how to only use the second one?


I have two taxonomies: "colours" and "shapes". I have a content type called "object" that has a field for "colour", and a field for "shape".

Then I have a simple view that lists content of type "object", and that has two contextual filters: one for "colour", and one for "shape".

If I go to /my-view/1, I get a list of all objects that are of colour "blue" (term id 1)

if I go to /my-view/1/5, I get a list of all the objects that are of colour "blue" and of shape "circle".

So far so good.

What however if I want to list all objects of shape "circle"? In other words, I only want to specify the second contextual filter. Obviously /my-view//5 doesn't work, so how can that be done?

(Note: I'm actually trying to do that programmatically by calling views_get_view_result("objects", "default", 1, 5). In the same way I can call views_get_view_result("objects", "default", 1), but I can't figure out how to call it with only the second contextual filter).

(Note2: I'm using Drupal 8, but it's actually the same with Drupal 7)


Solution

  • Never mind, even though I looked for the answer for a couple of days, I found it 5 minutes after posting...

    I need to specify an "exception" in the contextual filter - for example "all". Then I can go to /my-view/all/5, or call views_get_view_result("objects", "default", "all", 1)