Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Created May 8, 2018 17:21
facetwp replace display values in index
<?php
/** simple example of replacing values with new values in index
** rememember to reindex after adding code
**/
add_filter( 'facetwp_index_row', function( $params ) {
if ( 'post_type' == $params['facet_name'] ) { // 'post_type' should be replaced with your facet name
$current_values = array( 'Posts', 'Products' ); // array of values currently being used that you want to replace
$replace_values = array( 'Articles', 'For Sale' ); // array of values to replace with, values are in same order as above
@djrmom
djrmom / custom-hooks.php
Created May 8, 2018 17:30
facetwp replace display values on output
<?php
/** simple example of find and replace values in the output of a facet's html
** Be careful that this doesn't replace unwanted values, you may need to be more
** specific, such as including part of the surround html - '>Posts' to '>Articles' makes
** sure you target the word right after the processing <div> tag.
**/
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'post_type' == $params['facet']['name'] ) {
$current_values = array( 'Posts', 'Products' );
@djrmom
djrmom / custom-hooks.php
Last active February 19, 2019 16:57
facetwp allowinput datepicker
<?php
/** add js to footer to modify date_range options **/
add_action( 'wp_footer', function() { ?>
<script>
(function($) {
if ( 'undefined' !== typeof FWP ) {
FWP.hooks.addFilter('facetwp/set_options/date_range', function(flatpickr_opts, extras) {
flatpickr_opts['allowInput'] = true;
return flatpickr_opts;
@djrmom
djrmom / custom-hooks.php
Created May 10, 2018 23:50
facetwp replace date picker placeholder text
<?php
/** replace the "Date" or "Start Date" or "End Date" text in the datepicker
** Other langauges may have different text to replace as well
**/
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'my_date_facet' == $params['facet']['name'] ) { // change 'my_date_facet' to the name of your date picker facet
$output = str_replace( 'placeholder="Date"', 'placeholder="mm/dd/yyyy"', $output );
}
return $output;
@djrmom
djrmom / custom-hooks.php
Created May 16, 2018 15:06
facetwp change text by translating
<?php
/** example of changing a text string using wp's gettext filter **/
add_filter( 'gettext', function ( $translated_text, $untranslated_text, $domain ) {
if ( $translated_text == 'Enter location' && 'fwp' == $domain ) {
$translated_text = 'Other text';
}
return $translated_text;
}, 10, 3 );
@djrmom
djrmom / custom-hooks.php
Created May 17, 2018 13:53
facetwp beaver builder masonry
<?php
/**
** re-run masonry layout for beaver builder masonry post module after refreshing facets
**/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
var $element = 'undefined' == typeof element ? $( 'body' ) : $( element ),
@djrmom
djrmom / custom-hooks.php
Created May 18, 2018 13:11
facetwp modify facet count
<?php
/** removes () from count, could also be used to replace with alternate bracketing or other output **/
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'product_categories' == $params['facet']['name'] ) {
$output = preg_replace( '/\(([0-9]+)\)/', '$1', $output );
}
return $output;
}, 10, 2 );
@djrmom
djrmom / custom-hooks.php
Last active July 20, 2021 15:32
facetwp show/hide labels
<?php
add_action( 'wp_footer', function() {
?>
<script>
(function($) {
if ('object' !== typeof FWP) {
return;
}
$(function() {
@djrmom
djrmom / facet.css
Created May 18, 2018 19:01
facetwp listify css
/** fix slider in Listify */
.facetwp-type-slider .noUi-horizontal .noUi-handle.noUi-handle-upper {
left: auto !important;
}
@djrmom
djrmom / custom-hooks.php
Created May 22, 2018 17:00
facetwp uncode isotope
<?php
/**
** reload isotope for uncode theme after facet refresh
**/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {