- π©πͺGermany berliner
As per #1433622-3: Contextual filter AND (,) operator for multiple values does not work β this works if using "Content: Has taxonomy term ID" as a contextual filter.
- πΊπΈUnited States mark_fullmer Tucson
I verified that the comment in #12 works as expected. To summarize, if you want to have a single contextual filter accept multiple arguments, behaving as an AND filter rather than an OR filter, use the "Content: Has taxonomy term ID" contextual filter.
Seems like this could be marked as "Works as designed."
The description for "Allow multiple values" says that you can do OR and AND connections. Since AND is not working with the field-specific filter it is not working as intended, at least.
A minimal correction would be to change the description (see #6 π Contextual filter AND (,) operator for multiple values does not work Active ).
However, there is a difference between using a field-specific filter (as in the issue summary) and using "Has taxonomy term ID". The later checks for references anywhere in the entity, not just one specific field. So if your entity has two fields, which are using the same taxonomy, you can't create a filter like "all of the given terms (AND condition) must be given in field_foo". Therefore, enabling the AND-connection for field-specific filters might be helpful for this edge case.- π¨π¦Canada bisonbleu
There are solutions from contrib modules which make it possible to filter a view's results using e.g. arg1> AND arg2 in the URL like so: /product-profile/123,456.
For Node entities:
- https://www.drupal.org/project/views_taxonomy_term_name_into_id β
- https://www.drupal.org/project/views_taxonomy_term_name_depth βFor Commerce Product entities:
- https://www.drupal.org/project/commerce_product_taxonomy_filter β - πΊπΈUnited States miwayha
I'm dealing with the "edge case" described in #14. Comments #12, #13 and #15 do not appear to be helpful in resolving it. +1 for this being a bona fide issue that should be resolved.
- πͺπΈSpain alvolvfdez
I totally agree with comment #12. The solution is not to use βHas taxonomy term IDβ as this consumes the taxonomy_index table and not the entity table. This may generate other problems in terms of custom code (e.g. alterView) that is expecting a field name in the filter.
- π¬π§United Kingdom bluehead
Inherited a custom entity for further development and have the same problem. It's always OR no matter what syntax.
Eugene Bocharov β made their first commit to this issueβs fork.
This is a starting point to solve the issue. Though it should work for common use cases. But, for now, it will not work as expected if 'Exclude' option enabled. It should be possible to implement this as well using subquery. Also tests needed.
I've started issue fork and attaching the patch for 11.x. And, as I can see, it can be used with 10.2 too.
- Merge request !8141Resolve #3126078 "Contextual filter AND (,) operator for multiple values does not work" β (Open) created by Eugene Bocharov
Added logic for the 'Exclude' option. Tests are still needed.
- Status changed to Needs work
9 months ago 7:55pm 28 May 2024 May be this option has never worked as described in the setting description
"If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND)"
Earliest version of the module where I was able to find this option is Views 6.x-2.x-dev and there is almost the same logic as in current module state. Both '+' and ',' are implemented with OR logic.
Even tests in\Drupal\Tests\views\Kernel\ModuleTest
expect that values, divided by ',' will select items using OR.If so, and it's never worked other way, we should consider this functionality as a new feature and provide some extra setting to choose whether to use ',' for AND operator and '+' for OR, or both for OR as it works now. Otherwise we can break sites that relies on current behavior of ',' divider.