Created
December 4, 2018 10:03
-
-
Save ProjectKarol/344cd32d15db884aa636f28b89b4e3cf to your computer and use it in GitHub Desktop.
facetwp index geo my wordpress latitude/longitute
This file contains hidden or 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 | |
/** | |
* 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