Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. function get_lat_long($query)
  2. {
  3. if ( !is_admin() && $query->is_main_query() ) {
  4. if ($query->is_search) {
  5. $query->set('post_type', 'doctor');
  6. global $wpdb;
  7. if(isset($_GET['zipcode']) && isset($_GET['radius'])){
  8. $zipcode = (int)$_GET['zipcode'];
  9. $radius = (int)$_GET['radius'];
  10.  
  11. $lat_long = $wpdb->get_results("SELECT lat, lon FROM zips WHERE zip_code = '$zipcode' LIMIT 1");
  12. if($lat_long):
  13. global $minmax;
  14. $minmax = bar_get_nearby( $lat_long[0]->lat, $lat_long[0]->lon, 0, $radius );
  15. $minLat = $minmax['min_latitude'];
  16. $maxLat = $minmax['max_latitude'];
  17. $minLon = $minmax['min_longitude'];
  18. $maxLon = $minmax['max_longitude'];
  19. add_action( 'min_lat', function(){
  20. echo $minLat;
  21. });
  22.  
  23. add_filter( 'posts_where', function( $content ) use ( $minmax ){
  24. $where = " AND ( ( (geo.lat BETWEEN '$minmax[min_latitude]' AND '$minmax[max_latitude]') AND (geo.lng BETWEEN '$minmax[min_longitude]' AND '$minmax[max_longitude]') ) )";
  25. return $where;
  26. });
  27.  
  28. add_filter( 'posts_join', function(){
  29. global $wpdb;
  30. $join = " INNER JOIN wp_my_geodata AS geo ON ($wpdb->posts.ID = geo.post_id)";
  31. return $join;
  32. });
  33. endif;
  34. }else{
  35. return;
  36. }
  37. }
  38. }
  39. }
  40.  
  41. add_filter( 'pre_get_posts', 'get_lat_long');
  42.  
  43. add_filter( 'posts_where', function( $content ) use ( $minmax ){
  44. $where = " AND ( ( (geo.lat BETWEEN '$minmax[min_latitude]' AND '$minmax[max_latitude]') AND (geo.lng BETWEEN '$minmax[min_longitude]' AND '$minmax[max_longitude]') ) )";
  45. return $where;
  46. });
  47.  
  48. add_filter( 'posts_join', function(){
  49. global $wpdb;
  50. $join = " INNER JOIN wp_my_geodata AS geo ON ($wpdb->posts.ID = geo.post_id)";
  51. return $join;
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement