facetwp_facet_filter_posts to override slider logic

mgibbs189

{{gist file=”test.php” lang=”php”}}
<?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 );

{{/gist}}