Lat / Lng is stored in a meta field separated by a ,
called martygeocoderlatlng
Example Value 70.3280556,-150.9775001
Attempting to to separate this value into two variables _latitude
_longitude
to query the posts/products based on distance.
$products = new WP_Query(array(
$lat_lng = get_post_meta(get_the_ID(),'martygeocoderlatlng', TRUE),
$array = explode(',', $lat_lng),
$first = $array [0],
'geo_query' => array(
'lat_field' => $first,
Above does not not obtain the post meta field data. Would a possible solution be to merge two queries?
Below works but it requires lat/lng in separate fields.
$products = new WP_Query(array(
// $array => explode(',', 'martygeocoderlatlng'),
// $first = $array [0],
'geo_query' => array(
'lat_field' => '_latitude',
'lng_field' => '_longitude',
'latitude' => $page_latitude,
'longitude' => $page_longitude,
'distance' => 200,
'units' => 'miles'
),
'orderby' => 'distance',
'post_type' => 'product',
'posts_per_page' => 5,
'post_status' => array( 'publish', 'private'),
));