Wordpress Query for CPT that only shows posts within radius of current user's geolocation
I have a CPT called medical_providers. Each medical provider has two ACF meta_fields (latitude and longitude). I want to write a wp_query to only show medical providers that are within a certain range (100 miles?) of the current user's IP address. Here is my query so far. It does not include anything related to geolocation.
?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
global $wp_query;
$original_query = $wp_query;
$args = array(
'post_type' = 'medical_provider',
'posts_per_page' = 12,
'paged' = $paged,
'post_status' = 'publish',
'meta_key' = 'is_preferred',
'orderby' = 'meta_value',
'order' = 'DESC',
);
$the_query = new WP_Query( $args );
$wp_query = $the_query;
if ( $the_query-have_posts()) :
while ( $the_query-have_posts() ) : $the_query-the_post();
get_template_part( 'template-parts/medical-provider-content-post' );
endwhile;
?
Topic wp-query location-search Wordpress
Category Web