Filter a view based on a field being blank/empty

By: Michael Tidbury | Asked: 12/22/2022
ForumsCategory: How-toFilter a view based on a field being blank/empty
Michael Tidbury asked 1 year ago

I need to filter a view and only show entries when a particular dynamic field is empty (i.e. no value has been selected). I have achieved this by filtering on 'NOT like "a"' and 'NOT like "e"' because all possible values contain one or the other. Is there a neater way of achieving this so that the filter can be, for instance, a [get param="xxx"] where xxx is a or e? This way I can add it as an option on the search form at the top of the page. Many thanks, Michael.

1 Answers
Best Answer
Victor Font answered 1 year ago
The issue you have is that blank fields are not saved to the database so there's nothing to filter against when a field is empty. If you have it working by not searching for a specific value, I wouldn't change it. However, you could try filtering against not empty and you can certainly pass a parameter to a filter, so your get param idea will work.
Michael Tidbury replied 1 year ago

Aaah Victor, many thanks for the super speedy reply. I'm in England.

What you say makes perfect sense - I did not know that empty fields are not stored - it explains why on View there is an option to display empty fields.

I will stick to the filter solution then.

I can pass two parameters (lettera and lettere) with values of a and e respectively and it works perfectly.

However, the connundrum is how to convert, for instance, a single radio button (Field assigned - No) to two parameters lettera and lettere.

I have tried using [if xxx equals="No"]a[/if xxx] in the default value for a hidden field lettera and similarly for a hidden field lettere. However, when I pass the hidden fields as parameters they pass the conditional test itself and not the test result.

Do you have any thoughts on that?

All the best,


Victor Font replied 1 year ago

I have to question your use of the term "dynamic field" A dynamic field is a Pro lookup field that can be displayed in a variety of formats. The value of a dynamic field is an entry ID, which is numeric. The entry ID links the dynamic field's record id to the form field. There would never be an a or e in a dynamic value.

Michael Tidbury replied 1 year ago

Hi Victor,

The filter works fine; the field being filtered is Dynamic and the displayed value (from a look-up form) always contains an 'a' or an 'e'. This is proved because if I only filter for 'a' the displayed values with no 'a' but an 'e' come up.

To make it easier for the user, I want my search form to have a single radio button: 'Field empty' with 'Yes' as the only answer.

I have two hidden fields on the search form and I want to assign 'a' to one and 'e' to the other when the 'Field empty' has 'Yes' in it. These are then passed as the parameters.

How do I make the two hidden fields take on the 'a' or 'e' values when the radio button is ticked?

I tried making the default for the 'a' hidden field [if nnn equals="Yes"]a[/if nnn] where nnn is the number of the Field empty radio button. This passes a parameter of the whole text, i.e. it ignores the conditional statement.

I have got round it at the moment having two unnamed radio buttons: one when clicked has value 'a' and the other when clicked value 'e'. Then asking the user to tick both if they want to test for an empty field. It works fine but is clumbsy.

I'm sorry this is so long but hopefully it explains what is essentially a very simple business requirement 🙂

Bobby Clapp replied 1 year ago

Make the hidden fields conditional based on the radio. It's my understanding that if the condition doesn't allow the field to be save to the DB if the field doesn't show based on the condition.

Michael Tidbury replied 1 year ago

Hi Bobby,

Cunning...that idea works with the following modifications.

I have made the fields 'a' and 'e' text and visible only to the Administrator (a hidden field cannot be conditional so I had to hide the text fields from general view) and both conditional on the single 'Field empty' radio button.

It works perfectly.

Thank you to both you and Victor!

All the best,


Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community