FacetWP – index date based on UNIX timestamp

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

function fwp_index_timestamp( $params, $class ) {
if ( ‘class_start_date_range’ == $params[‘facet_name’] ) {
$raw_value = $params[‘facet_value’];

// basic timestamp validation
if ( is_numeric( $raw_value ) ) {
$ymd = date( ‘Y-m-d’, (int) $raw_value );
$params[‘facet_value’] = $ymd;
$params[‘facet_display_value’] = $ymd;
}
}
return $params;
}

add_filter( ‘facetwp_index_row’, ‘fwp_index_timestamp’, 10, 2 );
{{/gist}}