0

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'),
      
));
user2059376
  • 431
  • 5
  • 15
  • 1
    I'd use `meta_query`. [Here's the documentation](https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters). – Ruvee Oct 25 '21 at 20:22
  • [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/q/3653462/2943403) – mickmackusa Oct 25 '21 at 22:38

0 Answers0