<?php
// Also see: https://gist.facetwp.com/gist/fake-facet-choices/
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'event_month' == $params['facet']['name'] ) { // adjust name of facet
$values = (array) $params['values'];
$selected_values = (array) $params['selected_values'];
for ( $x = 0; $x < 12; $x ++ ) {
$time = strtotime( '+' . $x . ' months', strtotime( date( 'Y-M' . '-01' ) ) );
$key = date( 'Y-m', $time );
$name = date( 'F', $time );
$months[ $key ] = $name;
}
if ( empty( $selected_values ) ) {
$fake_output = '<div class="facetwp-radio checked" data-value="">All</div>';
} else {
$fake_output = '<div class="facetwp-radio" data-value="">All</div>';
}
foreach ( $months as $fake => $fake_display ) {
$key = array_search( $fake, array_column( $values, 'facet_value' ) );
if ( ! empty( $key ) || $key === 0 ) {
$selected = in_array( $values[ $key ]['facet_value'], $selected_values ) ? ' checked' : '';
$fake_output .= '<div class="facetwp-radio' . $selected . '" data-value="' . $fake . '"><span class="facetwp-display-value">' . $values[ $key ]['facet_display_value'] . '</span></div>';
} else {
$fake_output .= '<div class="facetwp-radio disabled" data-value="' . $fake . '"><span class="facetwp-display-value">' . $fake_display . '</span></div>';
}
}
$output = $fake_output;
}
return $output;
}, 10, 2 );