I have a custom post type for "Events" and each event can have a variable amount of "Locations" (lat/lng) which is stored as meta. I need to be able to get "Event" posts based on the bounds of a map.
I have full control over how I store the meta data of the locations for the post but I can't think of a way to create a meta_query to check against each location within an event to see if it fits within the min/max lat/lng.
Here's an example of what would work for a single location:
$args = array( 'post_type' => 'event', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'coords_0_lat', 'value' => array($lat_min, $lat_max, 'compare' => 'BETWEEN', 'type' => 'DECIMAL(10,7)' ), array( 'key' => 'coords_0_lng', 'value' => array($lng_min, $lng_max, 'compare' => 'BETWEEN', 'type' => 'DECIMAL(10,7)' ) ) ); $query = new WP_Query($args);
But since events can have any amount of locations I can't really just do coords_0..., coords_1..., coords_2..., etc.
I have found some information on filtering the "posts_where" to change the "where" into a "LIKE" rather than an "=" but from what I understand I don't think this would work in my case as it wouldn't keep the lat/lng of a location together. (Infromation here under "4. Sub custom field values")