I first experienced this issue with a website I'm building out, and I confirmed that I can recreate this error using the most recent Recommended (7.x-3.1) and Development (7.x-3.x-dev) versions of views (with both ctools 7.x-1.0-rc1 and ctools 7.x-1.x-dev).
What's the problem?
I have a vocabulary with, say, 20 terms. I have multiple nodes tagged with multiple terms from this vocabulary. I want to create a view that only displays nodes from 5 of these categories. So, I create a node type view with the following filters:
- published = published
- node type = page
- term IS ONE OF term A, term B, term C, term D, term E
The view works as expected. I am only shown nodes that are tagged in terms A-E.
Now, the issue arises when I want to allow the user to filter the results further, by choosing to display the nodes tagged by one of the 5 categories. So, I add another 'terms' filter, but this time expose it. (I have to add an extra filter here, as if I try to just exposed the previous term filter, by default it will show every node until an option is chosen). So, I add this new filter, and I choose
- selection type = drop-down
- operator = is one of
- select terms from vocabulary = term A, term B, term C, term D, term E
- limit list to selected items = checked
The view works as expected EXCEPT when the LAST term is selected (in example 'term E'). When the view result is filtered by the last option in the drop-down, no results are returned despite their being nodes that are tagged with this term.
What more can I tell you?
Not much, I'm a bit out of my depth. When I look at the view SQL, there is this strange line:
...AND field_data_field_aaaa2.field_aaaa_tid != '30' WHERE...
see in context here:
SELECT node.title AS node_title, node.nid AS nid, 'node' AS field_data_field_aaaa_node_entity_type
FROM
{node} node
INNER JOIN {field_data_field_aaaa} field_data_field_aaaa ON node.nid = field_data_field_aaaa.entity_id AND (field_data_field_aaaa.entity_type = 'node' AND field_data_field_aaaa.deleted = '0')
LEFT JOIN {field_data_field_aaaa} field_data_field_aaaa2 ON node.nid = field_data_field_aaaa2.entity_id AND field_data_field_aaaa2.field_aaaa_tid != '30'
WHERE (( (node.status = '1') AND (node.type IN ('page')) AND (field_data_field_aaaa.field_aaaa_tid IN ('28', '21', '30')) AND (field_data_field_aaaa2.field_aaaa_tid = '30') ))
ORDER BY node_title DESC
This is strange, because the last term id is 30, so if it's being precluded in this query with the !=30 - you're always going to get an empty result set.
I hope this write up is clear. Please let me know if I can clarify any further.
I have attached the export of the test view, if that's helpful, and a text file with the example SQL queries generated by the view.
Best Regards,
Olly
| Comment | File | Size | Author |
|---|---|---|---|
| exposed_filters_taxonomy_issue_sql.txt | 2.93 KB | baronmunchowsen | |
| exposed_filters_taxonomy_issue_export.txt | 7.57 KB | baronmunchowsen |
Comments
Comment #1
baronmunchowsen commentedApologies - to clarify, I can recreate this using a clean install of latest Drupal 7 with the views/ctools combinations mentioned above.
Comment #2
greta_drupal commentedI'm afraid that I have nothing meaningful to add for diagnostic or resolution. I just wanted to compliment baronmunchowsen for such a thoughtful, detailed post. Ran across it while searching for an issue that I am having. (I am doing something similar to this post, but haven't yet encountered any problems. But interested in the response from developer on this.)
Comment #3
chrbak commentedI am encountering exactly the same issue... The same strange line appears when i use the exposed filter of the same field :
and field_data_field_cat_poi2.field_cat_poi_tid != '686'And as a result when i select - from my exposed field - the last tag item (with tid=686) i get an empty result set.
In order to override this problem i thought the bellow solution (continuing the above well-aimed example):
I add to the vocabulary another term -> 'term F' with the id 687 which i am not actually using it. Then i selected in the filter view :
and added to the 'Filter Criteria' view the filter :
Like this i am able of choosing the last term because now the 'strange' line is :
and field_data_field_cat_poi2.field_cat_poi_tid != '687'I'll be waiting for a clear solution..
Comment #4
mustanggb commented