Last active
August 24, 2020 17:45
-
-
Save djrmom/67466579e53425d1638fcacf94fdf091 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| add_filter( 'facetwp_index_row', function ( $params, $class ) { | |
| if ( 'fecha' == $params['facet_name'] ) { | |
| $date = $params['facet_display_value']; | |
| $months_en = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); | |
| $months_es = array( 'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre' ); | |
| $date = str_replace( $months_es, $months_en, $date ); | |
| $date = date_create_from_format('j M, Y', $date); | |
| $date_formatted = date_format($date, 'Y-m-d'); | |
| if ( !empty( $date_formatted ) ) { | |
| $params['facet_value'] = $date_formatted; | |
| $params['facet_display_value'] = $date_formatted; | |
| } else { | |
| $params['facet_value'] = ''; // skip indexing | |
| } | |
| } | |
| return $params; | |
| }, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment