Last active
May 25, 2016 12:48
-
-
Save mgibbs189/659fd3172914c8e2e3860f920c7ccda5 to your computer and use it in GitHub Desktop.
FacetWP - treat number range like "max capacity"
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 fwp_max_capacity( $return, $params ) { | |
$facet_name = $params['facet']['name']; | |
if ( 'max_capacity' == $facet_name ) { | |
$values = $params['selected_values']; | |
$max_capacity = ( '' == $values[0] ) ? false : $values[0]; | |
global $wpdb; | |
if ( false !== $max_capacity ) { | |
$where .= " AND (facet_value + 0) >= '$max_capacity'"; | |
} | |
$sql = " | |
SELECT DISTINCT post_id FROM {$wpdb->prefix}facetwp_index | |
WHERE facet_name = '$facet_name' $where"; | |
return $wpdb->get_col( $sql ); | |
} | |
return $return; | |
} | |
add_filter( 'facetwp_facet_filter_posts', 'fwp_max_capacity', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment