0

I have a basic view that works great. It shows a list of nodes that are filtered by content type.

To that list of allowed content types, I want to add a taxonomy term. That is, the view should show anything that is a certain special content type, but ALSO include any node that has a certain special taxonomy term, no matter what the content type is.

The view that already works fine has its filter setup this way:

FILTER CRITERIA:

Content: Content type (is one of: Blog, IM, PI)

Easy, no problem. To add the taxonomy term, I set it up this way:

FILTER CRITERIA

    Content:  Content type (is one of: Blog, IM, PI)  OR
    Content: Has taxonomy term (= News Release) | Settings

Here's where it went all wrong on me. As soon as I added the taxonomy term filter, the items that should be there by Content Type completely disappeared. Only items with the taxonomy term show up in the view now. If I remove the taxonomy term filter, then items in the Content type pop back in again. It's like the taxonomy filter suppresses the content type filter in some way.

I tried:

  • using Content: Resource Type (= News Release) | Settings which was an alternate way of listing the taxonomy, "Resource Type" being the vocabulary
  • using AND instead of OR but, as you would expect, that returned no results at all because I do not have any of the special three content types that are also labeled as the special taxonomy "News Item". They are separate use cases.
  • using filter groups, listing the content type, an OR, and a content type AND taxonomy:

    Content:  Content type (is one of: Blog, IM, PI)
    OR
    Content: Content type (= Article) AND
    Content: Has taxonomy term (= News Release) | Settings
    

To be clear, either the node is a special content type OR the node is a regular content type with a special taxonomy term. Never both. Both types of nodes should appear side-by-side in this view.

Am I not allowed to make a view that shows stuff filtered by taxonomy alongside stuff filtered by content type at the same time? Can anyone suggest something for me to try?

  • 1
    what about using relationship to the taxonomy term ? drupal.org/docs/8/core/modules/views/… – Taggart Jensen Jan 9 at 7:17
  • @Taggart, I tried that and suddenly everything started working. Please put this as an answer and I'll mark it. – Leraa Jan 9 at 12:57
  • Please do post how you did it. I tried adding a Relationship to the field that references the term but it doesn't help. I tried some others too but nothing that changed the AND into OR in the query. – prkos Jan 9 at 21:20
  • At that link that @Taggart posted, they explain that a view is created with one table only. And that if you need to add something to the view that's NOT in that original table, it won't be able to see it. So the relationship thing lets you add more tables to the view. In my case, the starter table had to to with content type. Adding the taxonomy vocabulary table for the term i needed as a relationship made it work. – Leraa Jan 9 at 21:54
1

For others Solution is adding a views relationship see Documentation: https://www.drupal.org/docs/8/core/modules/views/add-a-relationship-to-a-view

enter image description here

  • This worked for me. For the circumstance in my original post, here is what I have on the right side, where @Taggart showed in the screenshot: RELATIONSHIPS field_taxonomy_resource_type: Taxonomy term I used default settings, I did not need to check the "Require this relationship" box or anything else. For my site, "Resource Type" is a taxonomy vocabulary. So the relationship was made with the vocabulary. – Leraa Jan 9 at 22:22
  • The Relationship you added is to the entity reference field towards a taxonomy term. You probably just named the field using the vocabulary name. I added the equivalent Relationship in my views, and I no longer have INNER JOIN, I only see LEFT JOINs, but still the operator is AND instead of OR. I seem to have the equivavlent views configuration, very simple, but I haven't been able to make it work so far. – prkos Jan 11 at 7:21
  • @prkos, you have the AND operator but you want the OR operator? Did you see where to change that? In the filter groups area that you get by using the dropdown menu in the "FILTER CRITERIA" section. Instead of Add, you choose "and/or rearrange" and that opens up the area where you can add filter groups and set things to AND and OR. – Leraa Jan 11 at 18:36
  • Yes, yes I have the OR in filters, just the two filters with OR, or I put them in separate groups with OR in between, and I have the Relationship, but inside the Query I always see AND, and there are no results. I haven't tried the patch though, maybe it doesn't only affect INNER joins. I don't know what might be different between our cases so it works for you but not for me. – prkos Jan 11 at 22:09
0

This is a bug, there are patches for different Drupal releases to fix the issue:

ManyToOneHelper ignores group configuration for some cases and forces INNER joins

Please report back in that Issue after you test so it can be marked as tested and included in the next release.

  • In my circumstance, the view was producing LEFT JOINs in the sql query. So I think that bug is not in this view. – Leraa Jan 9 at 22:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.