Gists

2 days ago
<?php

add_filter( 'facetwp_facet_sources', function( $sources ) {
    foreach ( $sources['custom_fields']['choices'] as $key => $value ) {
        if ( 0 === strpos( $value, '_stcr' ) ) {
            unset( $sources['custom_fields']['choices'][ $key ] );
        }
    }
    return $sources;
});
4 days ago
<?php

add_filter( 'facetwp_facet_render_args', function( $args ) {
    if ( 'program_days' == $args['facet']['name'] ) {
        $lookup = [];
        $temp_values = [];
        $days = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ];

        foreach ( $args['values'] as $row ) {
            $lookup[ $row['facet_value'] ] = $row;
        }

        foreach ( $days as $day ) {
            if ( isset( $lookup[ $day ] ) ) {
                $temp_values[] = $lookup[ $day ];
            }
            else {
                $temp_values[] = [
                    'facet_value' => $day,
                    'facet_display_value' => ucfirst( $day ),
                    'counter' => 0
                ];
            }
        }

        $args['values'] = $temp_values;
    }

    return $args;
});
1 week ago
/**
 ** adds is-hidden class to facetwp template to initial hide template.
 ** for use with conditional logic addon to show/hide template with
 ** conditions, prevents flash of content when hidden is the initial 
 ** state
 **/
add_filter( 'facetwp_shortcode_html', function( $output, $atts ) {

    if ( isset( $atts['template'] ) && 'my_template' == $atts['template'] ) { // change my_template to match your template
        $output = str_replace( 'class="facetwp-template"', 'class="facetwp-template is-hidden"', $output );
    }

    return $output; 

}, 10, 2 );
2 weeks ago
<?php

add_filter( 'facetwp_map_init_args', function( $settings ) {
    if ( isset( $settings['config']['cluster'] ) ) {
        $settings['config']['cluster']['maxZoom'] = 10;
    }
    return $settings;
});
2 weeks ago
<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'pais' == $params['facet_name'] ) {
        require_once PODS_DIR . 'classes/fields/pick.php';
        $pick = new PodsField_Pick();
        $countries = $pick->data_countries();
        $label = $params['facet_display_value'];
        if ( isset( $countries[ $label ] ) ) {
            $params['facet_display_value'] = $countries[ $label ];
        }
    }
    return $params;
}, 10, 2 );
3 weeks ago
<?php

add_filter( 'facetwp_facet_where', function( $where_clause, $facet ) {
    if ( 'categories_checkbox' == $facet['name'] ) {
        $name = $facet['name'];
        $tax = str_replace( 'tax/', '', $facet['source'] );
        $facets = FWP()->facet->facets;

        if ( isset( $facets[ $name ] ) ) {
            if ( ! empty( $facets[ $name ]['selected_values'] ) ) {
                $term_slug = $facets[ $name ]['selected_values'][0];
                $term = get_term_by( 'slug', $term_slug, $tax );
                if ( isset( $term->ID ) ) {
                    $where_clause .= " AND f.parent_id = '{$term->ID}'";
                }
            }
        }
    }
    return $where_clause;
}, 10, 2 );
3 weeks ago
<?php

// Add to your (child) theme's functions.php, and re-index afterwards

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'project_programs' == $params['facet_name'] ) {
        $val = $params['facet_value'];
        $val = preg_replace( '/^[a-z0-9]/', '-', $val );
        $val = preg_replace( '/[\-]+/', '-', $val );
        $params['facet_value'] = $val;
    }
    return $params;
}, 10, 2 );
1 month ago
<?php

add_action( 'wp_head', function() {
?>

<script>
(function($) {
    const isExternalURL = (url) => new URL(url).origin !== location.origin;

    document.addEventListener('facetwp-loaded', function() {
        $('.facetwp-template a').each(function() {
            var $this = $(this);
            if (isExternalURL($this.attr('href'))) {
                $this.attr('rel', 'nofollow');
            }
        });
     });
})(jQuery);
</script>

<?php
}, 100 );
1 month ago
<?php

add_action( 'wp_head', function() {
?>

<script>
(function($) {
    document.addEventListener('facetwp-loaded', function() {
        $(document).triggerHandler('ajaxComplete');
     });
})(jQuery);
</script>

<?php
}, 100 );
1 month ago
<?php

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    return $query->is_search() ? false : $is_main_query;
}, 10, 2 );