[Resolved] Pre-selection filter based on URL condition in View
This thread is resolved. Here is a description of the problem and solution.
Problem:
Setup default value of shortcode [wpv-control-post-taxonomy]
Solution:
The shortcode [wpv-control-post-taxonomy] does not support setup default value by shortcode attribute.
But it supports setup default value by URL parameter, in your case, you can try to pass URL parameter "wpv-lang" to the page, for example: https://mysite.com/page-url/?wpv-lang=en
You have a View that includes a filter for the checkboxes field with options for the language as shown in the screenshot, yes?
And you want that View to be filtered based on the language set in the URL?
You can add a Query Filter to the View for the checkboxes field and have its value come from a URL, but a URL parameter, so if the URL was mysite.com/?lang=fr then you could set the filter by the URL parameter "lang".
The same isn't directly possible with the URL format that you are currently using.
In that case you would need to provide the value for the filter by a shortcode attribute instead. You would need to use the legacy editor for Views to create the View and then insert it with the wpv-view shortcode, and add a custom attribute used by the filter, the value for which comes from a custom shortcode (you would need to write) that extracts the language code from the URL and returns just that part.
So if you registered a custom shortcode "language" that did that, you would insert your View like so
[wpv-view name="my-view" lang="[language]"]
and your Query Filter would be set up to get its value from the "lang" shortcode attribute.
I do want a solution that works with the current view. When the view filter is displaying all results. Is it possible to use JS to pre-select the option based on the URL on the first load and every time the AJAX refreshes?
Or I am thinking of using If-so plugin to see if that works. is there a way to preselect taxonomy with toolset view filter shortcode?
I think your custom JS codes is good, for the question: if it's sufficient?
That depends on yourself, if it can achieve your request, then it is sufficient