Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created May 15, 2019 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/e8c12df16260e527e36b77a0b7232128 to your computer and use it in GitHub Desktop.
Save mgibbs189/e8c12df16260e527e36b77a0b7232128 to your computer and use it in GitHub Desktop.
FacetWP - index GeoMyWP coordinates
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment