Skip to content

Instantly share code, notes, and snippets.

@ProjectKarol
Created December 4, 2018 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProjectKarol/344cd32d15db884aa636f28b89b4e3cf to your computer and use it in GitHub Desktop.
Save ProjectKarol/344cd32d15db884aa636f28b89b4e3cf to your computer and use it in GitHub Desktop.
facetwp index geo my wordpress latitude/longitute
<?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 {
return false;
}
}
return $params;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment