Gists

5 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 );
2 months 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 );
2 months 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 );
4 months ago
<?php

add_filter('facetwp_index_row', function( $params ) {
    $params['facet_display_value'] = wp_encode_emoji( $params['facet_display_value'] );
    return $params;
});
4 months ago
<?php

/**
 * 1. Add to your (child) theme's functions.php
 * 2. Assumes a facet named "doctor_location" w/ an ACF relationship field data source
 * 3. Assumes that the ACF Map field name is "location"
 */
add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'doctor_location' == $params['facet_name'] ) {
        $location_id = (int) $params['facet_value'];
        $location = get_field( 'location', $location_id );
        $params['facet_value'] = empty( $location ) ? '' : $location['lat'];
        $params['facet_display_value'] = empty( $location ) ? '' : $location['lng'];
    }
    return $params;
}, 10, 2 );
6 months ago
<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'stock' == $params['facet_name'] && 1 == $params['facet_value'] ) {
        $post_id = (int) $params['post_id'];
        $product = wc_get_product( $post_id );
        if ( 'instock' !== $product->get_stock_status() ) {
            $params['facet_value'] = 0;
            $params['facet_display_value'] = 'Out of Stock';
        }
    }
    return $params;
}, 10, 2 );
7 months ago
<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'country' == $params['facet_name'] ) {
        $details = $params['place_details'];
        $params['facet_value'] = $details['country'];
        $params['facet_display_value'] = $details['country'];
    }
    return $params;
}, 10, 2 );
8 months ago
<?php

/**
 * Posts have a "CPU" post object field (ACF)
 * CPUs have a "frequency" and "cores" field
 */
add_filter( 'facetwp_index_row', function( $params, $class ) {
	$name = $params['facet_name'];
	$cpu_id = (int) $params['facet_value'];

    if ( 'cpu_frequency' == $name ) {
		$params['facet_value'] = get_field( 'frequency', $cpu_id );
		$params['facet_display_value'] = get_field( 'frequency', $cpu_id );
	}
	elseif ( 'cpu_cores' == $name ) {
		$params['facet_value'] = get_field( 'cores', $cpu_id );
		$params['facet_display_value'] = get_field( 'cores', $cpu_id );
	}

    return $params;
}, 10, 2 );
8 months ago
<?php

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

add_filter( 'facetwp_index_row', function( $params, $class ) {
    $params['facet_value'] = remove_accents( $params['facet_value'] );
    return $params;
}, 10, 2 );
8 months ago
<?php

/*
 * 1. Add to your (child) theme's functions.php
 * 2. Replace "location" with the actual facet name
 * 3. Replace "latitude_longitude" with the actual custom field name
 * 3. Re-index afterwards
 */

add_filter( 'facetwp_index_row', function( $params, $class ) {
	if ( 'location' == $params['facet_name'] ) {
		if ( ! empty( $params['facet_value'] ) ) {
			$related_post_id = $params['facet_value']; 
            $coords = get_post_meta( $related_post_id, 'latitude_longitude', true );
            $lat_lng = explode( ',', $coords );

			$params['facet_value'] = $lat_lng[0];
			$params['facet_display_value'] = $lat_lng[1];
		}
	}
	return $params;
}, 10, 2 );