Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. add_filter( 'posts_where' , 'location_posts_where' )
  2.  
  3.  
  4. function location_posts_where( $where )
  5. {
  6. // $lat and $ lng are latitude and longitude of the searched point
  7. global $wpdb;
  8. $where .= " AND $wpdb->posts.ID IN (SELECT post_id FROM lat_lng_post
  9. WHERE
  10. (6371 * acos( cos( radians(" . $lat . ") )
  11. * cos( radians( lat ) )
  12. * cos( radians( lng )
  13. - radians(" . $lng . ") )
  14. + sin( radians(" . $lat . ") )
  15. * sin( radians( lat ) ) ) ) <= 150
  16. ORDER BY
  17. ( 6371 * acos( cos( radians(" . $lat . ") )
  18. * cos( radians( lat ) )
  19. * cos( radians( lng )
  20. - radians(" . $lng . ") )
  21. + sin( radians(" . $lat . ") )
  22. * sin( radians( lat ) ) ) ) ASC)";
  23. return $where;
  24. }
  25.  
  26. $args = array (
  27. 'post_type' => 'clinica',
  28. 'orderby' => 'none'
  29.  
  30. );
  31.  
  32. $args = array (
  33. 'post_type' => 'clinica',
  34. 'meta_key' => 'distance_field_name',
  35. 'orderby' => 'meta_value_num',
  36. 'order' => 'DESC'
  37. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement