This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$(document).on('click', '#reset', function() { | |
FWP.is_reset = true; | |
FWP.facets['my_facet'] = []; // set facet to no selections | |
delete FWP.facets['paged']; // remove "paged" from URL | |
FWP.refresh(); | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( 'my_facet' == $params['facet_name'] ) { // change my_facet | |
if ( !empty( $params['parent_id'] ) ) { | |
$params['facet_value'] = ''; // skip indexing | |
} | |
} | |
return $params; | |
}, 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** adds a "View All" index value to every post | |
** change 'my_radio' to the name of the radio facet to apply to | |
** 'View All' can be changed to whatever label is preferred | |
** reindex after add this code | |
**/ | |
add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) { | |
if ( 'my_radio' == $params['facet']['name'] ) { | |
$new_row = $params['defaults']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( 'sub_categories' == $params['facet_name'] ) { // change sub_categories to name of your facet | |
$parents = array( 18, 20 ); // change to ids of your parent terms | |
if ( ! isset( $params['parent_id'] ) || ! in_array( $params['parent_id'], $parents ) ) { | |
$params['facet_value'] = ''; // skip indexing | |
} | |
} | |
return $params; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* filter html for sort to output radio buttons | |
*/ | |
add_filter( 'facetwp_sort_html', function( $output, $params ) { | |
$output = '<div class="facetwp-sort-radio">'; | |
foreach ( $params['sort_options'] as $key => $atts ) { | |
$output .= '<input type="radio" name="sort" value="' . $key . '"> ' . $atts['label'] . '<br>'; | |
} | |
$output .= '</div>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( 'product_proximity' == $params['facet_name'] ) { | |
$latlng = $params['facet_display_value']; | |
if ( is_string( $latlng ) ) { | |
$latlng = preg_replace( '/[^0-9.,-]/', '', $latlng ); | |
if ( preg_match( "/^([\d.-]+),([\d.-]+)$/", $latlng ) ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* add additional source to select as Taxonomy Types | |
*/ | |
add_filter( 'facetwp_facet_sources', function( $sources ) { | |
$sources['posts']['choices']['tax_type'] = 'Taxonomy Types'; | |
return $sources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
** filter on facetwp_index_row to index only direct children of a parent term | |
** this is for use with Parent term setting which by default indexes child terms, and grand child terms, etc | |
** If you want to have the index include posts of child/grandchild, etc of terms, you need to set Hierarchical to yes | |
**/ | |
add_filter( 'facetwp_index_row', function( $params, $class ) { | |
if ( in_array( $params['facet_name'], array( 'my_facet', 'my_other_facet' ) ) ) { // create an array of facet names to check against | |
$parent = $class->facet['parent_term']; // this gives the parent term from the facet's settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(function($) { | |
/** | |
* creates a parent -> child -> grandchild dependency to disable facets | |
*/ | |
$(document).on('facetwp-loaded', function() { | |
if ('undefined' !== typeof FWP.facets['product_categories'] && FWP.facets['product_categories'].length < 1 ) { | |
$( '.facetwp-facet-product_tags select, .facetwp-facet-rating select').prop('disabled', 'disabled'); | |
} else if ('undefined' !== typeof FWP.facets['product_tags'] && FWP.facets['product_tags'].length < 1 ) { | |
$( '.facetwp-facet-rating select').prop('disabled', 'disabled'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
** facet classes | |
**/ | |
.facetwp-facet { | |
/* class of div that wraps each facet type */ | |
} | |
.facetwp-facet-FACET-NAME { | |
/* class for a facet where facet name is FACET-NAME, applied to same div as .facetwp-facet */ | |
} |