Skip Navigation

[Resolved] Shortcode-passed value and checkbox custom field

This support ticket is created 5 years, 6 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 9 replies, has 2 voices.

Last updated by ELAN42 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1273651

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.

#1273657

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?

#1275779

Invalid username, I'm unable to log in. Can you check?

#1275785

Please, try again now.

#1275925

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

#1276361

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?

#1276579
Screen Shot 2019-06-25 at 9.17.41 AM.png

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?

#1276591

Sorry, we're in heavy development!

Please try now... Thanks for the patience.

#1276621

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?

#1276685

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.