Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active August 24, 2020 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/6fa939f9ae739fa9f23cb6aaf7216fa9 to your computer and use it in GitHub Desktop.
Save djrmom/6fa939f9ae739fa9f23cb6aaf7216fa9 to your computer and use it in GitHub Desktop.
facetwp create custom range dropdown
<?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