Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Last active October 5, 2015 12:54
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 mgibbs189/fa5b9755f8f5d58381fc to your computer and use it in GitHub Desktop.
Save mgibbs189/fa5b9755f8f5d58381fc to your computer and use it in GitHub Desktop.
facetwp_facet_filter_posts to override slider logic
<?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