<?php
/**
* Setup instructions:
*
* 1. Add the following code to your (child) theme's functions.php
* 2. Create a new facet named "location"
* 3. Set the facet type to "Proximity"
* 4. Set the facet's Data source to "Post Type" (as a placeholder)
* 5. Save and re-index
*/
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'location' == $params['facet_name'] ) {
global $wpdb;
$post_id = (int) $params['post_id'];
$row = $wpdb->get_row( "SELECT latitude, longitude FROM {$wpdb->prefix}gmw_locations WHERE object_type = 'post' and object_id = '$post_id' LIMIT 1" );
if ( null !== $row ) {
$params['facet_value'] = $row->latitude;
$params['facet_display_value'] = $row->longitude;
}
}
return $params;
}, 10, 2 );