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 );
1 month ago
<?php
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( is_string( $params['facet_value'] ) ) {
$params['facet_value'] = str_replace( ',', '-', $params['facet_value'] );
}
return $params;
}, 10, 2 );
2 months ago
<?php
/** for when some entries are using & and some just & to standardize to keep
** facet from ending up with 2 facet_values that cause the same label to display in 2 choices
** generally happens with custom fields not taxonomies
** could be used for other encoded characters
**/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( strpos( $params['facet_display_value'], '&' ) > 0 ) {
$params['facet_display_value'] = str_replace( '&', '&', $params['facet_display_value'] ); // make & standard
$params['facet_value'] = str_replace( '&', '', $params['facet_display_value'] ); // remove & to prevent md5 hash
}
return $params;
}, 10, 2 );
4 months ago
<?php
/** fixes values based on term slugs to be numberic by looking up term name **/
add_filter( 'facetwp_index_row', function( $params, $class ) {
$term_id = (int) $params['term_id'];
$value = $params['facet_value'];
if ( 0 < $term_id && in_array( $class->facet['type'], [ 'number_range', 'slider' ] ) && !is_numeric( $value ) ) {
// lookup term name
$term = get_term( $term_id );
if ( !empty( $term ) ) {
$params['facet_value'] = $term->name;
}
}
return $params;
}, 11, 2 );
7 months ago
<?php
/**
* Usage:
*
* 1. Add the following to your (child) theme's functions.php
* 2. Create a new facet named "post_id"
* 3. Set its data source to "Post Type" (this serves as a placeholder)
* 4. Save and re-index
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'post_id' == $params['facet_name'] ) {
$params['facet_value'] = $params['post_id'];
$params['facet_display_value'] = $params['post_id'];
}
return $params;
}, 10, 2 );
9 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 );
9 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 );
11 months ago
<?php
add_filter('facetwp_index_row', function( $params ) {
$params['facet_display_value'] = wp_encode_emoji( $params['facet_display_value'] );
return $params;
});
12 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 );
1 year 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 );