Created
October 27, 2017 13:28
-
-
Save djrmom/5bd43ee83acc82048bb0dc5e0e52fde5 to your computer and use it in GitHub Desktop.
facetwp date source converted to year
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Amazing I just needed this to convert an Advanced Custom Fields (ACF) field date into one that FacetWP could understand.