Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
mgibbs189 / test.js
Created August 5, 2020 16:40
Show a reset button if any facets are in use
(function($) {
$(document).on('facetwp-loaded', function() {
var in_use = false;
// see if any facets are in use
$.each(FWP.facets, function(name, val) {
if (val.length > 0) {
in_use = true;
}
@mgibbs189
mgibbs189 / facet.js
Last active September 16, 2020 18:10 — forked from djrmom/custom-hooks.php
facetwp set order of (or remove) flyout facets
<?php
// Add to your (child) theme's functions.php, or into the Custom Hooks plugin!
add_action( 'wp_head', function() {
?>
<script>
(function($) {
FWP.hooks.addFilter('facetwp/flyout/facets', function(facets) {
@mgibbs189
mgibbs189 / functions.php
Last active July 27, 2020 19:02
FacetWP - create meta-choices
<?php
// Add to your (child) theme's functions.php and re-index afterwards!
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'recognition' == $params['facet_name'] ) {
$new_params = $params;
$label = $params['facet_display_value'];
if ( false !== strpos( $label, 'National Winner' ) ) {
@mgibbs189
mgibbs189 / functions.php
Created June 29, 2020 13:54
FacetWP - add the "URL prefix" setting temporarily
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_settings_admin', function( $settings, $class ) {
$settings['general']['fields']['prefix'] = [
'label' => __( 'URL prefix', 'fwp' ),
'html' => $class->get_field_html( 'prefix', 'dropdown', [
'choices' => [ 'fwp_' => 'fwp_', '_' => '_' ]
] )
@mgibbs189
mgibbs189 / functions.php
Last active June 22, 2020 19:09
FacetWP - date range - enable native datepicker
<?php
// Add the following to your (child) theme's functions.php
add_action( 'wp_footer', function() {
?>
<script>
(function($) {
if ( 'undefined' !== typeof FWP ) {
FWP.hooks.addFilter('facetwp/set_options/date_range', function(flatpickr_opts, extras) {
@mgibbs189
mgibbs189 / functions.php
Created June 18, 2020 15:29
FacetWP - use taxonomy for slider
<?php
// Add the following to your (child) theme's functions.php and re-index afterwards
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'gewicht' == $params['facet_name'] ) {
$params['facet_value'] = $params['facet_display_value'];
}
return $params;
}, 10, 2 );
@mgibbs189
mgibbs189 / functions.php
Last active June 17, 2020 14:06
FacetWP - merge data from different facets into one
<?php
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( in_array( $params['facet_name'], [ 'facet_2', 'facet_3', 'facet_4', 'facet_5' ] ) ) {
$params['facet_name'] = 'facet_1';
}
return $params;
}, 10, 2 );
@mgibbs189
mgibbs189 / test.php
Last active October 16, 2020 19:05
Show the reset button only when facets are active
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
var in_use = ('' != FWP.build_query_string());
$('.your-reset-btn').toggleClass('hidden', ! in_use);
});
})(jQuery);
</script>
@mgibbs189
mgibbs189 / functions.php
Last active June 15, 2020 16:00
FacetWP - sort options to include multiple fields
<?php
add_filter( 'facetwp_sort_options', function( $options, $params ) {
$options['points_desc'] = [
'label' => 'Points (Highest)',
'query_args' => [
'orderby' => [ 'date' => 'ASC', 'meta_value_num' => 'DESC' ],
'meta_key' => 'points'
]
];
@mgibbs189
mgibbs189 / functions.php
Created June 10, 2020 15:12
FacetWP - change number range "Min" and "Max" labels
<?php
// Add to your (child) theme's functions.php
add_filter( 'gettext', function( $translated_text, $text, $domain ) {
if ( 'fwp-front' == $domain ) {
if ( 'Min' == $translated_text ) {
$translated_text = 'Min (translated)';
}
elseif ( 'Max' == $translated_text ) {