Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_lat_long($query)
- {
- if ( !is_admin() && $query->is_main_query() ) {
- if ($query->is_search) {
- $query->set('post_type', 'doctor');
- global $wpdb;
- if(isset($_GET['zipcode']) && isset($_GET['radius'])){
- $zipcode = (int)$_GET['zipcode'];
- $radius = (int)$_GET['radius'];
- $lat_long = $wpdb->get_results("SELECT lat, lon FROM zips WHERE zip_code = '$zipcode' LIMIT 1");
- if($lat_long):
- global $minmax;
- $minmax = bar_get_nearby( $lat_long[0]->lat, $lat_long[0]->lon, 0, $radius );
- $minLat = $minmax['min_latitude'];
- $maxLat = $minmax['max_latitude'];
- $minLon = $minmax['min_longitude'];
- $maxLon = $minmax['max_longitude'];
- add_action( 'min_lat', function(){
- echo $minLat;
- });
- add_filter( 'posts_where', function( $content ) use ( $minmax ){
- $where = " AND ( ( (geo.lat BETWEEN '$minmax[min_latitude]' AND '$minmax[max_latitude]') AND (geo.lng BETWEEN '$minmax[min_longitude]' AND '$minmax[max_longitude]') ) )";
- return $where;
- });
- add_filter( 'posts_join', function(){
- global $wpdb;
- $join = " INNER JOIN wp_my_geodata AS geo ON ($wpdb->posts.ID = geo.post_id)";
- return $join;
- });
- endif;
- }else{
- return;
- }
- }
- }
- }
- add_filter( 'pre_get_posts', 'get_lat_long');
- add_filter( 'posts_where', function( $content ) use ( $minmax ){
- $where = " AND ( ( (geo.lat BETWEEN '$minmax[min_latitude]' AND '$minmax[max_latitude]') AND (geo.lng BETWEEN '$minmax[min_longitude]' AND '$minmax[max_longitude]') ) )";
- return $where;
- });
- add_filter( 'posts_join', function(){
- global $wpdb;
- $join = " INNER JOIN wp_my_geodata AS geo ON ($wpdb->posts.ID = geo.post_id)";
- return $join;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement