I have been trying to follow the docs here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
I have a numeric field ("last minute deals") in a custom post type and need to use a shortcode like this
[wpv-view name="last-minute-deals" lastminute="1"]
[wpv-view name="last-minute-deals" lastminute="0"]
Where "last-minute-deals" in the slug of my view and "lastminute" is the slug of the field. Alas, I only get "No results found", even if some of the contents do have a "1" for that field.
If you need access to the website, please see our previous tickets (supporter Minesh). Thank you.
Where can I see the View on the front-end of your site? Private information has been removed from your older tickets with Minesh, can you share again here?
Invalid username, I'm unable to log in. Can you check?
Okay thank you. I recreated the Query Filter and the checkbox=1 View is returning the correct results now. However, there is no easy way to filter by an "unchecked" checkbox using a shortcode attribute. Then you have two solution options:
1. Use a post ID exclusion filter
- Create a View of posts filtered by the checked checkbox. In the Loop, output the post IDs as a comma-separated list like 1,2,3,4 and remove the wrapping div from the output.
- Create another View of posts and add a post ID filter to exclude posts by ID, set by a shortcode attribute like "ids"
- Place View 1 inside the "ids" shortcode attribute of View 2. Now you have effectively filtered out all checked checkboxes, leaving only unchecked checkboxes in the results.
2. Use custom code to modify the query using compare type "NOT EXISTS". We have the wpv_filter_query API available for modifying the meta_query criteria programmatically. https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Thank you Christian,
Please, take with us a step backwards.
We didn't specify that we had been doing two different tests, one with a checkbox and the other with a numeric field.
Now, supposing we are completely fine ONLY with the numeric field (values 0 and 1), we have created this situation:
- One custom field (and only one), whose slug is "lastminutenumber"
- One view ("last-minute-deals") filtering according to the custom field and a shortcode param:
"Select items with field:
Last minute (numeric) is a number equal to VIEW_PARAM(lastminutenumber)"
The page is still this one, with three different attribute values (0, 1, empty):
hidden link
As you can see, it's not working as expected. Now, which is the correct way to filter results?
Not sure what's happening right now. None of the Appartamenti posts appear for me in wp-admin. Are you able to see any Appartamenti posts?
Sorry, we're in heavy development!
Please try now... Thanks for the patience.
Check now, I recreated the filter. Somehow there are two custom fields with similar names, and it looks like the wrong field was selected for the filter. Perhaps one is a similar generic field in a Form?
Thank you, the issue is solved. Anyway, we were not able to find the similarly-named field, not in any Field Group and not even in the Post Field Control page. We never used Forms on this website, so it looks like a DB inconsistency.
We'll be careful to only create such a field only once in the final website.