<?php
// index date as mmdd for example 1225
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'today' == $params['facet_name'] ) { // change today to name of your facet
$raw_value = $params['facet_value'];
$params['facet_value'] = date( 'md', strtotime( $raw_value ) );
$params['facet_display_value'] = date( 'F j', strtotime( $raw_value ) );
}
return $params;
}, 10, 2 );
// output only the facet choice for today with label of today, if
// there are none, this will be a ghost with show ghosts enabled
add_filter( 'facetwp_facet_render_args', function( $args ) {
if ( 'today' == $args['facet']['name'] ) {
$lookup = [];
$temp_values = [];
$days = [ date( 'md' ) ];
foreach ( $args['values'] as $row ) {
$lookup[ $row['facet_value'] ] = $row;
}
foreach ( $days as $day ) {
if ( isset( $lookup[ $day ] ) ) {
$temp_values[] = $lookup[ $day ];
}
else {
$temp_values[] = [
'facet_value' => $day,
'facet_display_value' => 'Today',
'counter' => 0
];
}
}
$args['values'] = $temp_values;
}
return $args;
});