Skip Navigation

[Closed] Help using Query Filter

This support ticket is created 4 years, 8 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Christian Cox 4 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1591109
query_filter2.jpg
query_filter.jpg

Tell us what you are trying to do? I am editing a view to add a Query Filter and i'm not sure if it's correct as it doesnt seem to work.
The query filter is based on a Custom Field Group (Private) that uses a check box. If the check box is marked then it has a value of 1.
I want the views to exclude all the posts that are Private, meaning have a value of 1. So I set it up to include all the posts with a value of blank for that specific field.

It doesnt seem to work.

Is there any documentation that you are following? https://toolset.com/documentation/user-guides/views/filtering-views-for-a-specific-text-string-search/

Is there a similar example that we can see? I saw a video tutorial for a similar function where you create a value of 1 for Premium cars.

What is the link to your site?
hidden link

#1591763

It's pretty difficult to filter out non-existent values from a custom search View. One way you could do it is to create a separate View of those posts with the custom field value = 1, and output a list of comma-separated post IDs. Then you could add a Query Filter in the original View that excludes posts by ID using a shortcode attribute "ids", and place the new View in the original View's ids shortcode attribute. Another option is to use custom code with the wpv_filter_query API to test for a custom field that does not exist. It's a bit tricky when you have a few other custom field filters. I think the post IDs exclusion filter is probably the most straightforward example. Let me know if you have questions about setting that up.

#1591891
query_filter2.jpg
query_filter.jpg

Hi Christian,

I am glad it is you who answered this question. It is actually a follow up to an old one that you also answered:
https://toolset.com/forums/topic/is-it-possible-to-set-some-products-as-private/

> It's pretty difficult to filter out non-existent values from a custom search View.
Maybe the problem is that I have assigned non existent values so I changed the parameters of the Custom Field and assigned a 1 if the checkbox is ticked and a 0 if not, whereas in the last version it had no value.

Please see my adjustments in the screenshot and let me know if I'm doing anything wrong. Basically I want to show all the posts that have a 0 value if not checked.

This is the first time that I use a Query Filter so I want to keep it as simple as possible.

Thank you

#1591909

I assigned a value of 0 if the box is not checked but the filter doesn't seem to work because all the posts are showing.

#1592023

Actually the "save 0 if not checked" option should not be used here. We learned this can cause problems for custom search, as explained in this erratum:
https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/
The suggestion from our other ticket about using a radio field is probably the simplest solution to implement if you are just starting a new project, or entering this field data for the first time.

The topic ‘[Closed] Help using Query Filter’ is closed to new replies.