<?php
// Choose the Post Date (or another date field) as the Slider facet's data source.
// Replace "my_slider_facet_name" with the name of your Slider facet.
// Do a full re-index.
// See: https://facetwp.com/help-center/facets/facet-types/slider/#create-a-year-slider
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'my_slider_facet_name' == $params['facet_name'] ) {
$raw_value = $params['facet_value'];
$params['facet_value'] = date( 'Y', strtotime( $raw_value ) );
$params['facet_display_value'] = $params['facet_value'];
}
return $params;
}, 10, 2 );