Last active
October 5, 2015 12:54
-
-
Save mgibbs189/fa5b9755f8f5d58381fc to your computer and use it in GitHub Desktop.
facetwp_facet_filter_posts to override slider logic
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 | |
function custom_slider_logic( $response, $params ) { | |
$facet = $params['facet']; | |
// Change the facet name | |
if ( 'YOUR_FACET_NAME' == $facet['name'] ) { | |
global $wpdb; | |
$values = $params['selected_values']; | |
$where = ''; | |
// Min value - CUSTOMIZE ME | |
if ( !empty( $values[0] ) ) { | |
$where .= " AND CAST(facet_value AS DECIMAL(10,2)) >= '{$values[0]}'"; | |
} | |
// Max value - CUSTOMIZE ME | |
if ( !empty( $values[1] ) ) { | |
$where .= " AND CAST(facet_display_value AS DECIMAL(10,2)) <= '{$values[1]}'"; | |
} | |
$sql = " | |
SELECT DISTINCT post_id FROM {$wpdb->prefix}facetwp_index | |
WHERE facet_name = '{$facet['name']}' $where"; | |
return $wpdb->get_col( $sql ); | |
} | |
return $response; | |
} | |
add_filter( 'facetwp_facet_filter_posts', 'custom_slider_logic', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment