Skip Navigation

[Resolved] Action hook that runs when a filter has been applied that includes which filters

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

Last updated by rusty 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#601618

I'm trying to create a previous/next navigation for single posts that 'remembers' the categories or keywords returned in the search results so the next/previous links on the single post page are the next and previous results from the filtering. I'm trying to do this without having a submit button and full page refresh.

Is there an action hook available that runs when a filter has been applied and the results are being updated with AJAX (not a full page refresh) and includes which filters are currently being applied somewhere in the arguments (since they would have otherwise been available in the URL for a full page refresh)?

Alternatively, is there is an event which fires client-side after the results are updated via AJAX and contains the filters currently being applied?

#601637
Screen Shot 2017-12-26 at 5.21.32 PM.png

Not sure I'm following you 100%, so please correct me if I've misunderstood your request.

Is there an action hook available that runs when a filter has been applied and the results are being updated with AJAX
In PHP, the wpv_filter_query hook callback is executed regardless of AJAX vs. full-page reloads. Any filters that are applied in the custom search form will be available in the $query_args parameter of this callback. Click the orange "More" button to see an example:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
I'm not quite sure how this will help you modify the Next / Previous links, though.

Alternatively, is there is an event which fires client-side after the results are updated via AJAX and contains the filters currently being applied?
The front-end event that is fired after the results are updated is 'js_event_wpv_parametric_search_results_updated' - but it doesn't have direct access to filters. Assuming the update modifies the URL with the new filters and criteria (select "Let me choose individual settings manually" in the Custom search settings to find the option to update the URL), you can access the updated URL in your JavaScript callback as data.permalink. Then you could parse that to collect URL parameters and append those parameters to the next / previous link URLs using custom JavaScript. In the View editor Filter editor panel, you will find a button that can help you insert an event callback function. See the attached screenshot. If you cannot see the Filter editor panel, you can click "Screen Options" at the top of the screen to enable the panel.

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
  console.log( data.permalink);  // <em><u>hidden link</u></em>
  // use jQuery here, not $, to modify the DOM based on the URL information
});
#602729

Sorry about the delay, Chris. This info was very helpful (particularly the data.permalink bit), but the client changed their spec. Thanks anyway!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.