How to Query for ACF Choices

Hi there, I would really like to see some examples for simple queries of ACF choices.

For example the true/false field.

I probably missed something obvious again :smiling_face_with_tear:

Some things around this are definitely broken at the moment.

We’re already discussing this question here: Filtering by ACF Field - #9 by avunu

Would appreciate knowing what is broken exactly

It doesn’t seem to me that we should need to use regex to filter for a simple 0/1, but maybe I’m missing something…

Let’s refrain using the word “broken” then.
There are many options inside the Query editor, and when making adjustments, we have to make sure we’re not removing features from another possible option. You cannot expect 0 and 1 to be automatically considered as integers, false and true as boolean etc…

While it is possible to filter choice fields, there may be improvements to be made in this direction.

Understood Louis. I wasn’t meaning to be overly forceful.

But perhaps I should be even more specific. If I add an integer all by itself to the meta value form, it doesn’t even save in the query.

Here’s what I mean:
image

This never hits the code editor:

I’ve verified that this query would work as rendered if the 0 was included.

I described this as broken since that would seem to be the most accurate/straight forward way to query a true/false ACF field, which was the subject of the post, and the query editor is clearly not honoring these inputs for some reason.

Thank you for the replies.

Hi, I thought that topic was unsolved because it included the filter block. I am looking for a simple example with posts that have the true value and to query for that.

Well my mistake would be to query the meta key as dynamic atribute the whole time instead of using the ACF field name :face_exhaling:

= also works as Meta compare field
true/false as Meta Value does not work!


This simple integration of a ACF field as the two images and possible values above could save a lot of time for others… especially for me :sweat_smile:

@Louis would something like this be a possible addition to the Documentation?

In 1.2.2.2, we have added a type selector in the Meta Value parameter that should allow you to convert values to your specific needs.

Please let me know if this helps solve the issues you were encountering up until now.

Hi @Louis,
not sure if the solution in 1.2.2.2 was meant for @avunu?

But I was “just” looking for simple query examples that could be added to the documentation, like a section Query examples or so.

My problem is that the documentation is missing some simple/complex examples as how to integrate queries. As with the question above before I had a dynamic value as my Meta Key which would never give me a functioning query result that this question needed.

With Cwicly frequent UI changes those examples would not be final and don’t need to be something fancy. Like in the solution above 2 images and further possibilities would suffice and if the UI changes, the logic how it works would still be there.

Well this would help me at least save many hours of random testing because I am missing something obvious :smiling_face_with_tear:

Thanks for this update BTW @Louis. It’s been very helpful! :heart:

1 Like