0

We're trying to create a view with a number of exposed filters in D7. There are a number of different content types that we want to show in the same view, and to filter using the same filters. However, most but not not all of the content types have all the fields we want to filter by.

For instance, "Difficulty Level" is a field common to many of our content types, including Tutorial and Project. However, an Idea does not have this field.

Ideally, we would like to let end-users filter by a number of fields and specify whether they want the filter to be strict or flexible. Let's say the user is looking for resources that have a Difficulty Level of "Beginner" or "Intermediate":

  • strict would mean that only nodes that fully satisfy the filters are shown:
    • no Ideas would be shown, because Ideas by definition don't have a Difficulty Level field to begin with
    • Tutorials with a Difficulty Level of null would also not show up
    • an Advanced Tutorial would not be shown
  • flexible would mean that all nodes that don't outright disagree with the filters are shown:
    • all Ideas would be shown
    • Tutorials with a Difficulty Level of null would be shown
    • an Advanced Tutorial would still not be shown

Is this doable with Drupal? I've searched high and low and haven't been able to find anyone with such a problem...

EDIT: Using the and/or groups is one possible solution, however it doesn't work for taxonomy fields: these lead to joins instead of left joins, so that you can either get the items that have the requested keyword or the items that don't have any keywords, but not both at the same time.

1

Yes, that's doable.

I would create a separate view for strict and flexible and then tailor each to suit your needs. You may need to use hook_views_query_alter if you can't get the functionality quite right with just the view UI.

A possible simpler alternative approach is outlined in this answer here.

Essentially this involves clicking on the reduce duplicates checkbox when configuring your join in the views UI.

| improve this answer | |
  • So the strict obviously isn't a problem, since it's an out-of-the-box behaviour - but how would you go about making the flexible one? Using and/or groups works for everything but taxonomies (which result in inner joins instead of left joins, so that you can either get the items that have the requested keyword or the items that don't have any keywords, but not both at the same time) – Alicja Z Mar 27 '14 at 16:44
  • This solution has worked for me in the past. – Felix Eve Mar 27 '14 at 16:48
  • If that doesn't work (or any other answers in that thread) then it's going to be a case of using hook_views_query_alter – Felix Eve Mar 27 '14 at 16:48
  • Thanks Felix - we actually went with pebbl's solution there, which is a bit easier to work with for us, but both would work. If you can edit your main answer to point to that page, I'll approve it :) – Alicja Z Mar 28 '14 at 10:11
  • Glad you got it working. Updated by answer :) – Felix Eve Mar 28 '14 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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