facetwp create custom range dropdown

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php

/** custom index to display a dropdown facet as a range
** change ‘CHANGE_ME’ to the name of your facet
** facet settings should be a dropdown type and the datasourc
** of the value you want to show as a range **/

add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘CHANGE_ME’ == $params[‘facet_name’] ) {
$price = $params[‘facet_value’];
switch ( true ) {
case ( $price < 10 ):
$params[‘facet_value’] = ’10’;
$params[‘facet_display_value’] = ‘Less than $10’;
break;
case ( $price <= 50 ):
$params[‘facet_value’] = ’50’;
$params[‘facet_display_value’] = ‘$10 to $50’;
break;
case ( $price > 50 ):
$params[‘facet_value’] = ‘100’;
$params[‘facet_display_value’] = ‘over $50’;
break;
default: // no value
$params[‘facet_value’] = ”; // skip indexing
}
}
return $params;
}, 10, 2 );
{{/gist}}