Client wants to hide some published content from specific Views displays.
Unpublishing the content is not an option: it needs to remain accessible.
I added a boolean exclude_from_view
field to several content types.
I planned to add a boolean filter to exclude content from the necessary displays if this field's value was TRUE
, but I was surprised to find that when I did so, Views returned no results at all. Setting the boolean filter to NOT FALSE
had the same result.
This is happening because the field has been added to the existing content without a default value, so the field returns NULL
, which is neither TRUE
nor FALSE
. (In PHP, NULL
is a "falsy" value, but apparently not to Views.)
A little research reveals that a lot of other people have complained about this problem.
Some of them think that boolean fields not set on entities should be considered FALSE
, not NULL
.
Others wish that NULL
fields could be treated as TRUE
.
Still others think that Views UI should offer filtering options for "Treat NULL
as FALSE
" or "Treat NULL
as TRUE
." (This is a cool idea but it requires patching core, which I'm not necessarily opposed to if it is the best way forward.)
What should I do?
UPDATE 2019-11-13:
Kudos to @no-sssweat for coming up with a viable workaround, which I upvoted below.
I'm still hoping for a better answer because I'm not satisfied with the user experience of the "checkboxes/radio buttons" field widget.
If I just use one value, it shows up as two radio buttons, for N/A and Yes. Adding a No option doesn't make it much better:
I think the client would really prefer a boolean checkbox, so I'm holding out for an answer that will give me that.