4 weeks ago
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_footer', function() {
?>
<script>
document.addEventListener('facetwp-refresh', function() {
if (FWP.loaded) {
FWP.setHash();
window.location.reload();
}
});
</script>
<?php
}, 100 );
6 months ago
document.addEventListener('facetwp-refresh', function() {
if (null !== FWP.active_facet) {
console.log(FWP.active_facet.nodes[0]);
}
});
8 months ago
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
document.addEventListener('facetwp-refresh', function() {
delete FWP.frozen_facets['sort_by'];
});
</script>
<?php
}, 100 );
10 months ago
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
document.addEventListener('facetwp-refresh', function() {
if (! FWP.loaded) {
FWP.hooks.addAction('facetwp/loaded', function() {
fUtil('.facetwp-type-fselect .facetwp-dropdown').each(function() {
fUtil(this).nodes[0].fselect.close();
});
}, 20);
}
});
</script>
<?php
}, 100 );
9 months ago
<?php
/** adds script to header
**/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (FWP.loaded && 'recipes' != FWP_HTTP.uri) { // if not the initial pageload, and we're on the homepage
window.location.href = '/recipes/?' + FWP.buildQueryString(); // redirect
}
});
})(jQuery);
</script>
<?php } );
2 years ago
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (! FWP.loaded) {
FWP.temp_set_hash = FWP.set_hash; // on init, save a backup of FWP.set_hash()
}
if (FWP.is_reset) {
FWP.set_hash = FWP.temp_set_hash; // on reset, store FWP.set_hash()
}
else {
FWP.set_hash = function() { /* empty */ } // otherwise, empty it
}
});
})(jQuery);
</script>
2 years ago
(function($) {
$(document).on('facetwp-refresh', function() {
if ( 'undefined' !== typeof FWP.facets['facet_1'] && FWP.facets['facet_1'].length > 0 ) {
FWP.facets['facet_2'] = FWP.facets['facet_1'];
FWP.facets['facet_1'] = [];
}
});
})(jQuery);
4 months ago
<?php
// Add to your (child) theme's functions.php
// To be able to set a custom default center (lat / lng) and/or zoom level in the Map facet's settings, the Google maps fitBounds function needs to be turne off.
// See: https://facetwp.com/help-center/facets/facet-types/map/#set-a-custom-zoom-level-or-location-center
// There are 2 options (add only one to your site):
// 1. Only on initial page load
add_action( 'wp_head', function() {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
if ('undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
FWP.hooks.addFilter('facetwp_map/fit_bounds', function(fit_bounds) {
return FWP.loaded; // force the custom lat/lng/zoom only on initial page load
});
}
});
</script>
<?php
}, 100 );
// 2. On every page load and facet refresh:
add_action( 'wp_head', function() {
?>
<script>
document.addEventListener('facetwp-refresh', function() {
if ('undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
FWP.hooks.addFilter('facetwp_map/fit_bounds', function(fit_bounds) {
return false; // force the custom lat/lng/zoom on every refresh
});
}
});
</script>
<?php
}, 100 );
2 years ago
<?php
/** sample of css and js to create a custom loading animation to cover the full facet area
** change #facet-container to a id or class of container element for your facets
** update css as needed
** please see https://facetwp.com/documentation/support/ for questions
**/
add_action( 'wp_head', function() { ?>
<style>
#facet-container {
position: relative;
}
.custom-loader {
position: absolute;
background-image: url("/path/to/image");
background-position: center;
background-repeat: no-repeat;
}
</style>
<?php });
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (FWP.loaded) {
$('#facet-container').prepend('<div class="custom-loader facetwp-loading"></div>');
$('.custom-loader').height( $('#facet-container').height() ).width( $('#facet-container').width() );
}
});
$(document).on('facetwp-loaded', function() {
$('.custom-loader').remove();
});
})(jQuery);
</script>
<?php
},100);
12 months ago
<?php
// Add to your (child) theme's functions.php file
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (! FWP.loaded) {
FWP.setHash = function() { /* empty */ }
}
});
})(jQuery);
</script>
<?php
}, 100 );