Overview

This JS event gets triggered before FacetWP begins the refresh process. It happens before any AJAX is requested, and before the URL hash gets updated. This event is useful for modifying any FWP variables before getting sent to the server.

Usage

Override a facet value:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_action( 'wp_footer', function() { ?> <script> document.addEventListener('facetwp-refresh', function() { FWP.facets['vehicle_type'] = ['car']; // force a specific value }); </script> <?php }, 100 );

Clear facet A’s value if a value for facet B is selected:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_action( 'wp_footer', function() { ?> <script> document.addEventListener('facetwp-refresh', function() { if (FWP.facets['facet_b'].length > 0) { FWP.facets['facet_a'] = []; } }); </script> <?php }, 100 );

More examples

See also