2

I have a views block that displays related nodes based on tags. (See Entity Reference get nodes based on tags.) The comment links to the solution I found.

Now, I have to add another filter to the view.

Some of the related nodes have a date field (start and end date), and some do not. When I add a filter to exclude nodes where end dates have come and gone, no related nodes without the date field is shown.

How is it possible to filter out nodes where the end date is greater or equal to now on nodes with the date field, but still show nodes that do not have the date field?

1

Problem is in the very SQL. No date field in node means null value in result set. Any logical operation with null ends up returning null, see manual. And null is a logical false for conditions. So, each time you test a date to see what are OK, MySQL excludes them - lack of date is not a date in acceptable range.

If views would support negative filtering (exclude matching), it would be just as you want it. But views support only positive filtering (include only matching).

Enough of diagnosis, time for solution! On the block's header Filter criteria you have a dropdown with add seelcted. Drop it down and use And / Or, rearrange. Make your filters OR, and after date limit add some other filter, one that will return true for no-end-date nodes. Here comes the tricky part - you can select the same field multiple times, but you cannot use null in place of date. If nodes without a date are simply of another content type, you are good. If they are of the same type, you have a problem - I'll add solution for that particular case if I'll find it.

  • Thank you, that seems to do the trick! This is how my filter criteria looks like now: evernote.com/shard/s323/sh/f5d8f03a-7764-4c38-8f5d-cbca8cd4c9d4/… – pusle May 15 '13 at 11:52
  • Looks good. I would try to pull content published and content language to the front, to have them in one place only, for the sake of readability and consistency. Like that: published AND language AND ( content_without_date OR (content_with_date AND date_ok ) ) but the final result should be the same. – Mołot May 15 '13 at 11:56
  • Aha! That would be easier to read yes. Thanks for the tip. And, thanks very much for your help! – pusle May 15 '13 at 11:59

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.