WP_Query posts by distance based on LAT & LNG in Database

I’ve got table in the WordPress database that has lat & lng stored and I’d like to add a sort feature on the results page ‘Sort by Distance’ that gets the locations that are closer to your provided lat & lng. I’m using WP_Query, it needs to work with it. Thanks 🙂

                $my_query = new WP_Query( array(
                'post_status' => 'publish',
                'post_type' => 'post', 
                'category__in' => $category,
                'tax_query' => array(
                        'relation' => 'AND',
                        array(
                            'taxonomy' => 'age',
                            'field' => 'id',
                            'terms' => $age,
                            'operator' => 'IN'
                        ),
                        array(
                            'taxonomy' => 'price',
                            'field' => 'id',
                            'terms' => $price,
                            'operator' => 'IN'
                        ),
                        array(
                            'taxonomy' => 'group',
                            'field' => 'id',
                            'terms' => $group
                        )
                    ),
                'posts_per_page' => '-1',
                ) );

Related posts

Leave a Reply

1 comment