My Resource Library at hidden link displays the Resources custom post type with user selected filters. The 'All Organizations' filter (second one listed inline) should filter by the 'wpcf-doc_organization-author' custom field via 'url_param="wpv-wpcf-doc_organization-author"' I would like the ability to allow the User to select from three fields in the Select dropdown: "All Organizations" (everything), "GCPEA" (only those with GCPEA as the meta value), and "Other Organizations" (only those NOT with GCPEA as the meta value).
I tried different code formats to try to get this functional but I'm unable to. My latest code for that filter is:
[wpv-control-postmeta values=",GCPEA,'( $(wpcf-doc_organization-author) ne 'GCPEA' )'" display_values="All Organizations,GCPEA,Other Organizations" field="wpcf-doc_organization-author" type="select" source="custom" url_param="wpv-wpcf-doc_organization-author"]
Would you be able to help me get this functional? Thank you in advance!
Hello,
There isn't such kind of built-in feature within Toolset Views/Blocks plugin, see our document:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-control-postmeta
You can not use conditional statement within Views [wpv-control-postmeta] shortcode.
But you can enable option "Show only available options for each input" in section "Custom Search Settings", see my screenshot options.JPG.
Above option will show only available options by view's result
Thanks for letting me know. I didn't see a screenshot attached to your message. Could you share with me, please?
I have uploaded the screenshot options.JPG, please check it
To confirm, are you saying there's no workaround for the ability to allow the User to select from three fields in the Select dropdown: "All Organizations" (everything), "GCPEA" (only those with GCPEA as the meta value), and "Other Organizations" (only those NOT with GCPEA as the meta value)?
As I mentioned above, you can not use conditional statement within Views [wpv-control-postmeta] shortcode, if you want to limit the options by available results, you can try the option "Show only available options for each input".
So how do I limit options by one value and the other being a single value that represents all other values that are not the first value?
To avoid more misunderstanding, please elaborate the question with more details:
So how do I limit options by one value and the other being a single value that represents all other values that are not the first value?
What single value do you want to represent? How do you setup the custom fields in posts?
The option "Show only available options for each input" depends on the search result, it will show search options which are available in the search result, and hide search options automatically which does not present in the search result, see my screenshot:
https://toolset.com/wp-content/uploads/2021/07/2124849-options.jpg
And in shortcode [wpv-control-postmeta] you can setup default option "All" with the attribute "default_label", like this:
[wpv-control-postmeta type="select" field="wpcf-doc_organization-author" default_label="All" url_param="wpv-wpcf-doc_organization-author"]
More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-control-postmeta
default_label (opt):
'default option text'
Add default option like All or Any on taxonomy select control.
What I want to do is provide two Select options for the 'wpcf-doc_organization-author' custom field: one that contains a meta value of "GCPEA" author and one that contains all other values that are NOT "GCPEA" author. In other words, I want the user to be able to filter by: =GCPEA or !=GCPEA.
I understand that I cannot have a conditional rule within the [wpv-control-postmeta] shortcode, but I wanted to ask if you were familiar with a workaround that would provide me with what I'm looking for? Thank you in advance!
For the question:
In other words, I want the user to be able to filter by: =GCPEA or !=GCPEA
Yes, it is possible with custom codes, for example:
After user submit the search form, you can use wpv_filter_query to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
In this PHP function, get the wpcf-doc_organization-author input value:
hidden link
If it is "!=GCPEA", then setup view's query to what you want:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
Thank you for this info. Last question: would these custom codes work if the View filter's custom search settings is "AJAX results update when visitors change any filter values" rather than requiring visitors to click the Search button?
Yes, custom codes with "wpv_filter_query" filter hook will work when option "AJAX results update when visitors change any filter values" is enabled.