Skip Navigation

[Résolu] Views filter to display data from Repeatable field group

This support ticket is created Il y a 5 années et 8 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 3 réponses, has 2 voix.

Last updated by webD-3 Il y a 5 années et 8 mois.

Auteur
Publications
#1079833

I have set up a Repeatable Field Group for my custom post type.

One of the fields is a simple checkbox.

Value To Store is 1.

Save Option is set to "Save 0 to Database".

I am intending to have two views on my single CPT post, one that displays the items that have that box checked, and one that displays the items that have the box unchecked.

The first view works fine, with this Custom Field filter:

Select items with field:
Department Head is a number equal to 1

This returns the items that have the box checked, as expected.

However, I am having trouble figuring out what the Custom Field filter should be for the items that have the box unchecked.

I tried this:

Select items with field:
Department Head is a number equal to 0

However, the only way I am getting the items to display is to first check the box, save, and then uncheck the box and save again. Only at that point, does Views see that the field value is 0.

Is there something I can do to filter for unchecked items without having to check and uncheck?

#1079834

More information:

I can confirm via PHPMyAdmin that the unchecked items are not saving a 0 to the database.

When I originally set up the checkbox in the Repeating Field Group, the "Don't save anything to database" option was selected.

But I have since changed it and new items that have been added, after I changed that setting to "Save 0 to Database", are still not saving anything to the database.

If there's a way to correct that, that's good. But if not, is there a filter that allows me to select everything that isn't exactly "1", including no value at all?

#1080212

1. Checkboxes or any other field that offers the "Save 0 to Database" won't work in Views.
We wil remove it completely in future.
https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/

I hence have to recommend to not store 0 in those fields

2. The not in filter is something that we requested a while ago from our developers, however the issue is, if you store nothing, WordPress makes no entry, and we cannot search by things that do not exist (not yet)

I will add your voice there
The main issue is that if you add a Filter by such a field, the View will return ALL results in the begin - that is fine, but only ALL results that actually HAVE such value stored.
It will not display the posts that have no such value stored, because well, all posts that have such value are already found - and can at this point be filtered by some values, in the view.
But not those without any value.

I added your vice to the feature request that asks for such filters.

#1081378

Beda, thank you for the reply.

Now that I know that this is a known issue, I moved on with an alternate approach and resolved this for my specific case within 5 minutes.

I merely deleted the checkbox field from the Custom Fields Group, and then immediately created a radio button field with the same slug and the same "1" and "0" values, setting the default selection to 0. This way all the RFG items that had the checkbox selected still had 1, but now all the other items would be assigned 0. Finally, I went back into each of my posts and simply hit Update, to save that 0 value for each of the items. I didn't have to edit any of the items, nor did I have to edit the View.

Thanks for your help!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.