facetwp index geo my wordpress latitude/longitute

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php

/**
* select post type in the map or proximity facet as the datasource, this is just a placeholder
* looks up lat/lng from GEO my WordPress plugin tables
* do a full re-index in facetwp’s settings to update the indexed values after adding code
*/
add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘my_map_facet’ == $params[‘facet_name’] ) { // be sure to change this to the name of your facet
global $wpdb;

$sql = $wpdb->prepare( “SELECT latitude, longitude FROM {$wpdb->prefix}gmw_locations WHERE object_id = %d AND object_type = ‘post’ LIMIT 1″, $params[‘post_id’] );
$result = $wpdb->get_row( $sql );

if ( null !== $result ) {
$params[‘facet_value’] = $result->latitude;
$params[‘facet_display_value’] = $result->longitude;
}
else {
$params[‘facet_value’] = ”; // skip indexing
}
}
return $params;
}, 10, 2 );
{{/gist}}