<?php
/*
* 1. Add to your (child) theme's functions.php
* 2. Replace "location" with the actual facet name
* 3. Replace "latitude_longitude" with the actual custom field name
* 3. Re-index afterwards
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'location' == $params['facet_name'] ) {
if ( ! empty( $params['facet_value'] ) ) {
$related_post_id = $params['facet_value'];
$coords = get_post_meta( $related_post_id, 'latitude_longitude', true );
$lat_lng = explode( ',', $coords );
$params['facet_value'] = $lat_lng[0];
$params['facet_display_value'] = $lat_lng[1];
}
}
return $params;
}, 10, 2 );