contextual filter: Taxonomy term: Term ID

I have tried all variations with specifying criteria, with one or more vocabularies, always allowing multiple values: There is never a difference between 'Filter to items that share all terms' and 'any terms'. Both of them filter to any.

Do I miss something? Pretty sure I was able to do so some month ago.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Hitby’s picture

Hi suldan,
Did you get this working?

Thanks

mzgajner’s picture

Wow, I came here looking for a solution, but my problem both options filter to all.

ygerasimov’s picture

I would like to reproduce the problem locally. Can you please guide how to set up the view and what is expected behavior and what we have instead?

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

@ygerasimov
You are doing really great work in the issue queue. Feel free to set the status to "postponed (needs more info)".
If noone responds for a long time we can close them all at once, which happens for many issues.

suldan’s picture

@ygerasimov
Thanks for taking a look:

1. We need a taxonomy with some terms (A and B)
2. 2 nodes each related to term A and B; 1 node related to only A
3. The view with:
a. relationship 'Content: Taxonomy terms on node'
b. argument '(term) Taxonomy term: Term ID' [default value: taxonomy ID from url; default filter from node page; reduce by vocabulary; Filter to items that share all terms

expected behavior: When viewing a node related to A+B the view should return one node (also related to terms A+B).

actual behavior: All nodes related to A or B are returned

esmerel’s picture

Are you sure you set the filter to 'and' not, 'or'? Check your settings in the filters.

jooplaan’s picture

I could reproduce the bug. Filter criteria is set to 'AND', same configuration as in comment #5. Any solution is highly appreciated.

esmerel’s picture

Status: Postponed (maintainer needs more info) » Active
bdevore’s picture

Just ran into this myself. What you're missing is under the "More" tab on the contextual filter at the bottom of the modal window, select "allow multiple values".

esmerel’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dbrouard’s picture

Just for you to know, I yet have the same problem, both options do the same 'Filter to items that share all terms' and 'any terms'.

My workaround is setting two contextual filters, one for every vocabulary.

zhuber’s picture

Issue summary: View changes

This is actually not working for me.

I have 'Filter to items that share all items' and 'allow multiple values' selected.

If I inspect the args in a preprocess_views_view function I see that the args have the following:
3,5,18

Unfortunately, it is matching any item instead of matching all.

zhuber’s picture

Status: Closed (fixed) » Needs work
FileSize
58.15 KB

Not trying to hijack the thread here, but both dbrouard and myself have the same issue.

When I select 'Filter to items that share all terms' and 'Allow multiple' it still shows items that match any (OR instead of AND).

My use case:

Taxonomy:

Automobile
- Car
- Sedan
- Coupe
- Truck

If I have my view block on a node with "Car, Sedan" selected my view will return results from nodes tagged with "Car", "Car, Coupe", etc. It does not limit to items with both "Car" AND "Sedan".

Attaching screenshots, here is the query:

SELECT DISTINCT node.promote AS node_promote, field_data_field_popularity.field_popularity_count AS field_data_field_popularity_field_popularity_count, node.nid AS nid
FROM 
{node} node
INNER JOIN {field_data_field_type} field_data_field_type ON node.nid = field_data_field_type.entity_id AND (field_data_field_type.entity_type = 'node' AND field_data_field_type.deleted = '0')
LEFT JOIN {field_data_field_categories} field_data_field_categories ON node.nid = field_data_field_categories.entity_id AND (field_data_field_categories.entity_type = 'node' AND field_data_field_categories.deleted = '0')
LEFT JOIN {field_data_field_popularity} field_data_field_popularity ON node.nid = field_data_field_popularity.entity_id AND (field_data_field_popularity.entity_type = 'node' AND field_data_field_popularity.deleted = '0')
WHERE (( (field_data_field_categories.field_categories_tid IN('3', '5', '18') ) )AND(( (node.status = '1') AND (node.type IN  ('poi')) AND (field_data_field_type.field_type_value = 'discover') )))
ORDER BY node_promote DESC, field_data_field_popularity_field_popularity_count DESC
LIMIT 5 OFFSET 0

As you can see, it is selecting any items in an array of IDs:
WHERE (( (field_data_field_categories.field_categories_tid IN('3', '5', '18')

zhuber’s picture

Status: Needs work » Closed (fixed)

Found the issue.

I was using a taxonomy field as my contextual filter (field_category).

By switching to a 'Has taxonomy term ID' contextual filter, this functionality worked fine.