Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Last active May 25, 2016 12:48
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/659fd3172914c8e2e3860f920c7ccda5 to your computer and use it in GitHub Desktop.
Save mgibbs189/659fd3172914c8e2e3860f920c7ccda5 to your computer and use it in GitHub Desktop.
FacetWP - treat number range like "max capacity"
<?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