JavaScript hooks and events
Overview
WPEnhanced Ajax Filter Blocks updates the Archive Loop over AJAX. Front-end scripts that initialize UI inside loop items must re-run after each update. The plugin exposes a jQuery event and related globals for this purpose.
This reference covers practical patterns—not every internal function, which may change between releases.
Primary event: divi_filter_completed
After a filter request completes and loop HTML is applied, the plugin triggers:
jQuery.event.trigger({ type: 'divi_filter_completed' });
Listen with:
jQuery(document).on('divi_filter_completed', function () {
// Loop DOM is updated; safe to re-init third-party scripts
});
When it fires
- Standard filter changes (taxonomy, meta, price, search, etc.)
- Pagination within the filtered loop
- Load More and infinite scroll append operations (Pro)
- Reset filters (when the loop re-renders)
When to use it
| Use case | Example |
|---|---|
| Re-init galleries | Lightbox, PhotoSwipe, theme gallery |
| Lazy load | Intersection Observer on new images |
| WooCommerce | wc_variation_form() on new product cards |
| Analytics | Track filter interactions after DOM settle |
| Custom carousels | Swiper / Slick on injected slides |
See also Run JavaScript after AJAX.
Registration best practices
(function ($) {
function onFilterCompleted() {
// Your logic
}
$(function () {
$(document).on('divi_filter_completed', onFilterCompleted);
});
})(jQuery);
- Register once on document ready.
- Avoid heavy synchronous work—defer large DOM scans.
- Guard third-party calls with
typeofchecks if optional plugins may be inactive.
Related globals
The plugin may expose helper functions on window for compatibility with Divi Ajax Filter-derived codebases, including:
| Global | Purpose |
|---|---|
divi_filter_params | Update selected-filter chip UI when customizing filter parameter display |
divi_filter_params_array | Batch chip updates |
handle_conditional_fields | Re-evaluate conditional filter visibility (Pro) |
show_hide_reset | Toggle reset button visibility after apply |
Rely on divi_filter_completed for most integrations; use globals only when extending chip UI or conditional filters.
DOM selectors
Filter UI commonly uses these containers (useful for scoped re-init):
| Selector | Element |
|---|---|
.divi_filter_module | Filter Posts wrapper |
#divi_filter | Main filter root ID |
.filter-param-item | Active filter chips |
.search_filter_cont | Individual filter item container |
Loop output is replaced inside the Archive Loop block wrapper—scope queries to that container when possible.
No native CustomEvent (currently)
The completion signal is a jQuery event on document, not a standard window CustomEvent. Use jQuery or bridge manually:
jQuery(document).on('divi_filter_completed', function () {
window.dispatchEvent(new CustomEvent('ajaxFilterBlocksCompleted'));
});
Debugging
Enable browser Network tab to confirm REST responses return 200. Use Console to log inside your divi_filter_completed handler and verify it runs on each filter change.
What's next
- PHP hooks — Server-side filters and actions
- Run JavaScript after AJAX — Customer-facing summary
- Filters not updating — When events never fire