Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'posts_where' , 'location_posts_where' )
- function location_posts_where( $where )
- {
- // $lat and $ lng are latitude and longitude of the searched point
- global $wpdb;
- $where .= " AND $wpdb->posts.ID IN (SELECT post_id FROM lat_lng_post
- WHERE
- (6371 * acos( cos( radians(" . $lat . ") )
- * cos( radians( lat ) )
- * cos( radians( lng )
- - radians(" . $lng . ") )
- + sin( radians(" . $lat . ") )
- * sin( radians( lat ) ) ) ) <= 150
- ORDER BY
- ( 6371 * acos( cos( radians(" . $lat . ") )
- * cos( radians( lat ) )
- * cos( radians( lng )
- - radians(" . $lng . ") )
- + sin( radians(" . $lat . ") )
- * sin( radians( lat ) ) ) ) ASC)";
- return $where;
- }
- $args = array (
- 'post_type' => 'clinica',
- 'orderby' => 'none'
- );
- $args = array (
- 'post_type' => 'clinica',
- 'meta_key' => 'distance_field_name',
- 'orderby' => 'meta_value_num',
- 'order' => 'DESC'
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement