Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Last active August 25, 2020 16:01
facetwp index file extension
<?php
/** index a url or file path value as the extension to create a file type facet
** facet datasource needs to be a value that contains a url or file path for the file that includes the file extension
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_facet_name' == $params['facet_name'] ) {
$raw_value = $params['facet_value'];
$extension = end( explode ( '.', $raw_value) );
if ( !$extension )
@djrmom
djrmom / custom-hooks.php
Last active August 25, 2020 16:00
facetwp yes not
<?php
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'walking_mobility' == $params['facet_name'] ) {
if ( "No" == $params['facet_display_value'] ) {
$params['facet_value'] = ''; // skip indexing
} elseif ( "Yes" == $params['facet_display_value'] ) {
$params['facet_display_value'] = 'Walking Mobility';
}
}
@djrmom
djrmom / custom-hooks.php
Created September 12, 2017 12:48
facetwp count only
<?php
/**
** output only total results
**/
add_filter( 'facetwp_result_count', function( $output, $params ) {
$output = $params['total'] . ' results';
return $output;
}, 10, 2 );
@djrmom
djrmom / facet.js
Last active April 19, 2018 16:17
facetwp redirect on change
(function($) {
$(document).on('change', '.facetwp-facet-product_tags', function() { // change product_tags to name of dropdown facet
FWP.parse_facets();
FWP.set_hash();
var query = FWP.build_query_string();
window.location.href = '/search-results/?' + query; // search-results to correct page
});
})(jQuery);
@djrmom
djrmom / custom-hooks.php
Created September 21, 2017 13:54
facetwp select and refresh after loaded
<?php
function fwp_preload_facets() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
if ( '' == FWP.build_query_string() && 'shop' == FWP_HTTP.uri) {
FWP.is_reset = true;
FWP.facets['product_categories'] = ['clothing'];
@djrmom
djrmom / facet.js
Created September 22, 2017 12:58
facetwp redirect category selection
(function($) {
$(document).on('facetwp-refresh', function() {
if ( 'fr/accueil' == FWP_HTTP.uri && 'undefined' !== typeof FWP.facets['categories'] && FWP.facets['categories'].length > 0 ) {
var query = FWP.build_query_string();
window.location.href = '/search-results/?' + query;
}
});
})(jQuery);
@djrmom
djrmom / custom-hooks.php
Created September 27, 2017 13:02
facetwp check if any facets are selected
<?php
/**
* adds js code to check for any facets being selected
*/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
var facets_in_use = function() {
var in_use = false;
@djrmom
djrmom / facet.js
Created September 27, 2017 13:07
facetwp check a single facet
<script>
(function($) {
/**
* check if a facet exists but is empty, change 'categories' to name of the facet being checked
*/
$(document).on('facetwp-loaded', function() {
if ('undefined' !== typeof FWP.facets['categories'] && FWP.facets['categories'].length < 1 ) {
// do something if facet is empty
}
});
@djrmom
djrmom / facet.js
Last active October 5, 2017 16:21
facetwp disable top level checkboxes
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-type-checkboxes').children('.facetwp-checkbox').addClass( 'disabled ');
});
})(jQuery);
@djrmom
djrmom / custom-hooks.php
Last active February 18, 2019 19:18
facetwp add expanded class to checkboxes
<?php
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(function() {
FWP.hooks.addAction('facetwp/loaded', function() {
$('.facetwp-type-checkboxes .facetwp-depth.visible').prev('.facetwp-checkbox').toggleClass('expanded');
}, 100 );
});