Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / custom-hooks.php
Last active February 22, 2018 01:16
facetwp convert colors
<?php
/**
** facetwp's color addon uses either HTML colors names (HTML color names) or hex values
** the following can map color values that aren't saved in the correct format for indexing
** remember to do a full re-index in facetwp's settings after adding your code
** check the wp_facetwp_index table in your database if you need to verify indexing is in the
** correct format
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'colors' == $params['facet_name'] ) { // change 'colors' to the name of your facet
@djrmom
djrmom / custom-hooks.php
Created February 22, 2018 16:48
facetwp sort by term_order
<?php
add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
if ( 'my_facet' == $facet['name'] ) { // change 'my_facet' to name of your facet
/** get you terms in the term_order and make a list of them in the form:
** $ordered_terms = '"term_slug_1", "term_slug_2", "term_slug_3"';
** note that the double quotes need to be part of the variable itself
** so that that it will output a string as shown in
** https://facetwp.com/documentation/facetwp_facet_orderby/ "Sort by arbitrary values" **/
<?php
add_filter( 'facetwp_index_row', function ( $params, $class ) {
if ( 'fecha' == $params['facet_name'] ) {
$date = $params['facet_display_value'];
$months_en = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
$months_es = array( 'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre' );
$date = str_replace( $months_es, $months_en, $date );
$date = date_create_from_format('j M, Y', $date);
$date_formatted = date_format($date, 'Y-m-d');
@djrmom
djrmom / custom-hooks.php
Created February 26, 2018 18:13
facetwp listings template
<?php
/** add 'facetwp' => true to the listing facetwp template query args **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'listings' == FWP()->helper->get_uri() && true !== $query->get( 'facetwp' ) ) {
return false;
}
return $is_main_query;
}, 10, 2 );
@djrmom
djrmom / archive-product.php
Created March 1, 2018 17:48
facetwp woocommerce template
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@djrmom
djrmom / custom-hooks.php
Created March 7, 2018 23:44
facetwp add facetwp-template to downloads shortcode
<?php
/** filters download shortcode to wrap text for 0 results in facetwp-template class
** text may need to be adjust to match site setting
**/
add_filter( 'downloads_shortcode', function( $output, $atts ) {
$output = str_replace( 'No Products found', '<div class="facetwp-template">No Products found</div>', $output );
return $output;
}, 20, 2 );
@djrmom
djrmom / custom-hooks.php
Last active February 18, 2019 19:18
facetwp modify slider label
<php
/** add js to wp_head to modify slider **/
add_action( 'wp_head', function() { ?>
<script>
(function($) {
$(function() {
FWP.hooks.addAction('facetwp/set_label/slider', function($this) {
var label = $this.find('.facetwp-slider-label').html();
var regex = /(^[^\s]+)/;
@djrmom
djrmom / facetwp.css
Created March 22, 2018 01:53
facetwp use image in fselect
div[data-value="facet-value"] .fs-option-label {
background: url(http://example.com/content/uploads/2018/02/some-image.jpg) 0 0 no-repeat;
background-size: contain;
padding-left: 20px;
}
@djrmom
djrmom / custom-hooks.php
Created April 3, 2018 16:56
facetwp jetpack lazy load compat
<?php
/** reinitializing jetpack's lazy load after facet loads **/
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
jetpackLazyImagesModule( $ );
});
@djrmom
djrmom / custom-hooks.php
Last active April 5, 2018 19:19
facetwp check lanague
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( false !== $query->get( 'lang' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );