Add the ability to combine AND and OR logic to contextual filters

Created on 4 February 2022, about 3 years ago
Updated 27 March 2023, almost 2 years ago

Problem/Motivation

In some situations or requirements, one needs to combine OR and AND logic on their contextual filters.

Proposed resolution

Add the ability to combine AND and OR logic to contextual filters like it's done on standard views filters.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain rcodina Barcelona

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada chrisck BC, Canada

    +1 for this much needed feature!

  • 🇦🇹Austria maxilein

    You can achieve that when you are using tokens on views filter using

    Tokens in Views Filter Criteria

    and maybe also this module: https://www.drupal.org/project/token_filter

  • I'm also interested in this. It's not even clear what the default behavior is. Forums seem to indicate "AND" to be the default.

  • 🇨🇦Canada chrisck BC, Canada

    @maxilein Your suggestion may not work for everyone. In our case we are needing flexibility around AND/OR logic around the contextual filter from fields of the current entity.

  • 🇨🇴Colombia jasonac91

    While the proposed solution seems promising, it would be helpful to have more detailed information regarding the specific use cases and testing scenarios where combining AND and OR logic in contextual filters would be applied. Could you please provide some examples or documentation that illustrates the expected behavior in various contexts? This information would be crucial for fully understanding the potential impact and implementation challenges of this feature.

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    A possible use case I could see:

    A related products block with 3 contextual filters

    On the product entity.
    - Product category (single value)
    - Product type (single value)
    - Product tags (multivalue)

    Contextual filters (with target_ids as example):
    - Product category (1+2)
    OR
    - Product type (3+4)
    AND
    - Product tags (5+6)

    This way you are able to retrieve products that match either the category 1 or 2 OR product type 3 or 4, but need (AND) to have tag 5 or 6.

Production build 0.71.5 2024