<?php
add_filter( 'facetwp_facet_render_args', function( $args ) {
if ( 'program_days' == $args['facet']['name'] ) {
$lookup = [];
$temp_values = [];
$days = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ];
foreach ( $args['values'] as $row ) {
$lookup[ $row['facet_value'] ] = $row;
}
foreach ( $days as $day ) {
if ( isset( $lookup[ $day ] ) ) {
$temp_values[] = $lookup[ $day ];
}
else {
$temp_values[] = [
'facet_value' => $day,
'facet_display_value' => ucfirst( $day ),
'term_id' => 0,
'parent_id' => 0,
'depth' => 0,
'counter' => 0
];
}
}
$args['values'] = $temp_values;
}
return $args;
});
// Or, to add different values for 'facet_value' and 'facet_display_value':
add_filter( 'facetwp_facet_render_args', function( $args ) {
if ( 'business_country' == $args['facet']['name'] ) {
$lookup = [];
$temp_values = [];
$items = [
'england' => 'England',
'scotland' => 'Scotland',
'wales' => 'Wales',
'northern-ireland' => 'Northern Ireland',
'ireland' => 'Ireland'
];
foreach ( $args['values'] as $row ) {
$lookup[ $row['facet_value'] ] = $row;
}
foreach ( $items as $key => $value ) {
if ( isset( $lookup[ $key ] ) ) {
$temp_values[] = $lookup[ $key ];
}
else {
$temp_values[] = [
'facet_value' => $key,
'facet_display_value' => $value,
'term_id' => 0,
'parent_id' => 0,
'depth' => 0,
'counter' => 0
];
}
}
$args['values'] = $temp_values;
}
return $args;
});