Last active
August 24, 2020 17:48
-
-
Save djrmom/6fa939f9ae739fa9f23cb6aaf7216fa9 to your computer and use it in GitHub Desktop.
facetwp create custom range dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment