Created
May 15, 2019 16:12
-
-
Save mgibbs189/e8c12df16260e527e36b77a0b7232128 to your computer and use it in GitHub Desktop.
FacetWP - index GeoMyWP coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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