Last active
August 24, 2020 17:45
-
-
Save djrmom/e9a340873ad5451d2bffe16f590dfc06 to your computer and use it in GitHub Desktop.
facetwp convert prices to price ranges
This file contains hidden or 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 | |
| add_filter( 'facetwp_index_row', function ( $params, $class ) { | |
| if ( 'my_facet' == $params['facet_name'] ) { // change 'my_facet' to facet name | |
| if ( $params['facet_value'] > 10000 ) { | |
| $new_params = $params; | |
| $new_params['facet_value'] = 50000; | |
| $new_params['facet_display_value'] = 'Less than 50000'; | |
| $class->insert( $new_params ); // insert each value to the database | |
| } | |
| if ( $params['facet_value'] > 5000 ) { | |
| $new_params = $params; | |
| $new_params['facet_value'] = 10000; | |
| $new_params['facet_display_value'] = 'Less than 1000'; | |
| $class->insert( $new_params ); // insert each value to the database | |
| } | |
| /** more checks for additional values **/ | |
| $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