I have a post type View that displays its search form as a list of radio buttons (terms). It's for an intranet site which means the terms are dynamic. I.e., the terms can be created or deleted by users. I used ajax to display the search results (posts that belongs to the terms).
Now, similarly, I'd like to use ajax to reload the search form (the radio buttons / terms). Is there any way to achieve this?
By the way, I've already tried the following:
1.) Using "render_view" from the View API, but it doesn't reload the latest terms. For example, if a term is deleted by a user, the render_view function still includes the term from previous filter. Further, the function displays both the search form and results. Since I'm already using ajax to display the results, Im only interested in the search form.
2.) I use jquery to reload a div around the View search form but it ended up returning a blank section.
Thanks.
Hi, there's not a good way update filter options on-the-fly using AJAX like this in Views. Results can be updated with AJAX, as you have mentioned, but updating the filter options requires a full page reload. Are you concerned that people will have the search form page open for a long period of time, and filter options will be changed frequently during that period of time? Or is there a separate concern? I would like to understand what you want to accomplish to see if there's a different solution available.
Hi Christian, thanks for replying.
You're right. Since it's an intranet site with hundreds of concurrent users at one time, it's very likely the search options will change. I have ensured that page is reloaded every few seconds for now but its not visually appealing. Any filter hooks I can use for my own ajax function? I looked into wpv_filter_query but it seems to only filter the results. I look forward to your response.
We offer the following filters you could explore.
1. wpv-view-settings, which allows you to modify View settings, like filter meta html, on-the-fly:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_view_settings
2. wpv-filter-start-filter-form and wpv-filter-end-filter-form, which allow you to prepend or append content to the filter controls:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_start_filter_form
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_end_filter_form
Again, these filters are intended for use with full page reloads so issues arising from using them with AJAX to update filter options on-the-fly will not be supported here in the forum. If you'd like, I can file a feature request to enhance Views with the ability to update filter controls using AJAX. Let me know how you envision this working. For example, is there a refresh button somewhere in the controls that triggers these updates, or a predefined timer refresh, or is it refreshed with any search, etc.