Gists

by mgibbs189 - 3 years ago

<?php

// Set the facet's Data source to "Post Type" as a placeholder

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'is_beer_on_tap' == $params['facet_name'] ) {
        if ( is_beer_available( $params['post_id'] ) ) {
            $params['facet_value'] = 'on-tap';
            $params['facet_display_value'] = 'On tap';
        }
        return false; // don't index anything else
    }
    return $params;
}, 10, 2 );

by mgibbs189 - 2 weeks ago

<?php

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

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'gewicht' == $params['facet_name'] ) {
        $params['facet_value'] = $params['facet_display_value'];
    }
    return $params;
}, 10, 2 );
by mgibbs189 - 2 weeks ago

<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( in_array( $params['facet_name'], [ 'facet_2', 'facet_3', 'facet_4', 'facet_5' ] ) ) {
        $params['facet_name'] = 'facet_1';
    }

    return $params;
}, 10, 2 );
by mgibbs189 - 6 months ago

<?php

// Add the following to your (child) theme's functions.php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'region_partner' == $params['facet_name'] ) {
        $params['facet_name'] = 'region_dropdown'; // trick FacetWP into saving values into the other facet
    }
    return $params;
}, 10, 2 );

by djrmom - 1 month ago

<?php

/**
 * reindex after adding or updating this filter
 */
add_filter( 'facetwp_index_row', function( $params, $class ) {
	if ( 'my_facet' == $params['facet_name'] ) { // change my_facet to your facet's name/slug
		if ( '1' == $params['facet_value'] ) { // be careful with 1 and 0 as values - https://www.php.net/manual/en/types.comparisons.php
		    $params['facet_display_value'] = 'My Label'; // text to display in the facet choices
        	}
	}
	return $params;
}, 10, 2 );

by djrmom - 7 months ago

<?php 

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'my_facet_name' == $params['facet_name'] ) { // change my_facet_name to the name of your facet
        $params['facet_value'] = "1";
        $params['facet_display_value'] = 'Has Term'; // change Has Term to whatever you want for a label
    }
    return $params;
}, 10, 2 );
by mgibbs189 - 7 months ago

<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'job_company' == $params['facet_name'] ) {
        if ( ! empty( $params['facet_value'] ) ) {
            $post = get_post( (int) $params['facet_value'] );
            $params['facet_value'] = $post->post_name;
        }
    }
    return $params;
}, 10, 2 );

by mgibbs189 - 8 months ago

<?php

// Add the following to your (child) theme's functions.php file
// Then re-index afterwards

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'country' == $params['facet_name'] && 2 == strlen( $params['facet_value'] ) ) {
        $params['facet_display_value'] = locale_get_display_region( '-' . $params['facet_value'], 'en' );
    }
    return $params;
}, 10, 2 );

by mgibbs189 - 9 months ago

<?php

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

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'YOUR_FACET_NAME' == $params['facet_name'] ) {
        $params['facet_display_value'] = str_replace( '&', '&', $params['facet_display_value'] );
        $params['facet_display_value'] = str_replace( '&', '&', $params['facet_display_value'] );
        $params['facet_display_value'] = str_replace( '&', '&', $params['facet_display_value'] );
    }
    return $params;
}, 10, 2 );

by mgibbs189 - 9 months ago

<?php

/**
 * This will trick FacetWP's indexer into indexing "tags_list" values for the "categories_new" facet
 *
 * Re-index after adding the following code into your (child) theme's functions.php
 */
add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'tags_list' == $params['facet_name'] ) {
        $params['facet_name'] = 'categories_new';
    }
    return $params;
}, 99, 2 );