<?php
/**
* Receives a field with dates split by commas and record each one individualy.
* This way, one post will appear in different dates.
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
// @TODO: change 'your_facet_name' by your facet's name.
if ( 'your_facet_name' === $params['facet_name'] ) {
// Dates split by comma, perhaps with white-space.
$values = $params['facet_value'];
// Remove white-spaces.
$values = str_replace(' ', '', $values);
// Transform it in array.
$values = explode(',', $values);
// Loop through values adding each date.
foreach ( $values as $val ) {
// Update the values to be inserted into database.
$params['facet_value'] = $val;
$params['facet_display_value'] = $val;
// Insert each value to the database.
$class->insert( $params );
}
// Skip the default indexing query.
return false;
}
return $params;
}, 10, 2 );