FacetWP index year and month

mgibbs189

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

/**
* reindex after adding or updating this filter
*/
add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘date_as_month_year’ == $params[‘facet_name’] ) { // change date_as_year to name of your facet
$raw_value = $params[‘facet_value’];
$params[‘facet_value’] = date( ‘Y-m’, strtotime( $raw_value ) ); // “2019-04” for the permalink
$params[‘facet_display_value’] = date( ‘F Y’, strtotime( $raw_value ) ); // “April 2019” for the display value
}
return $params;
}, 10, 2 );
{{/gist}}