Skip to content

Instantly share code, notes, and snippets.

@BryanBarrera
Forked from djrmom/custom-hooks.php
Created November 12, 2020 02:46
Show Gist options
  • Save BryanBarrera/d88c30f7845e4ee02e0c9726029ef274 to your computer and use it in GitHub Desktop.
Save BryanBarrera/d88c30f7845e4ee02e0c9726029ef274 to your computer and use it in GitHub Desktop.
facetwp date source converted to year
<?php
/**
* reindex after adding or updating this filter
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'date_as_year' == $params['facet_name'] ) { // change date_as_year to name of your facet
$raw_value = $params['facet_value'];
$params['facet_value'] = date( 'Y', strtotime( $raw_value ) );
$params['facet_display_value'] = $params['facet_value'];
}
return $params;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment