How to Disable Facet Auto-Refresh and Add a Submit Button
FacetWP automatically refreshes whenever any interaction happens, but it’s possible to disable this if needed:
Prevent the auto-refresh
To prevent FacetWP’s auto-refresh functionality, add the following code to your (child) theme’s functions.php or into the Custom Hooks add-on:
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
<?php add_action( 'wp_footer', function() { ?> <script> (function($) { $(function() { if ('undefined' !== typeof FWP) { FWP.auto_refresh = false; } }); })(fUtil); </script> <?php }, 100 );
Add an “Apply” or “Submit” button/link to your page
After disabling the auto-refresh functionality, you can add a button to your page to let the user manually apply all facet selections made. You can style the button however you wish. The important part is that the FWP.refresh()
method is triggered on click:
<button onclick="FWP.refresh()">Apply</button>
You can also use a link:
<a href="javascript:;" onclick="FWP.refresh()">Apply</a>
Trigger a refresh with a Sort facet
In the above setup with a Submit button, if you also have a Sort facet, you may want to trigger a direct refresh when using it, without having to use the Submit button.
Add the following code to your (child) theme’s functions.php to trigger a refresh after any changes to the Sort facet:
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
<?php add_action( 'wp_head', function() { ?> <script> (function($) { $(document).on('change','.facetwp-type-sort select', function() { FWP.refresh(); }); })(jQuery); </script> <?php }, 100 );