lp__distance
lp__distance is a custom query parameter used in the Launchpad Core plugin to handle distance-based queries for posts. This parameter enables you to filter posts based on their proximity to a specific geographic location.
Product
How it Works
The lp__distance parameter enables location-based filtering by retrieving posts based on their proximity to a given latitude and longitude. It allows queries to dynamically calculate geographic distances and filter results efficiently.
Launchpad Core allows storing custom data in a custom table optimized for spatial queries, rather than relying on post meta. This ensures faster and more scalable distance-based filtering, making it ideal for handling large datasets.
Accepted Arguments
lp__distance accepts an associative array with the following keys:
- latitude (float) – The latitude of the reference point. Default:
0. - longitude (float) – The longitude of the reference point. Default:
0. - value (float) – The distance value to use in the comparison. Default:
0. - compare (string) – The comparison operator for filtering posts by distance. Possible values:
>,<,>=,<=,=,!=. Default:<.
Usage
You can use lp__distance in your custom code to perform location-based filtering of posts. It accepts latitude, longitude, distance value, and comparison operators to define geographic criteria for your query.
Example
$args = array(
'post_type' => 'rep_listing', // Replace with your custom post type
'lp__distance' => array(
'latitude' => 40.7128, // Latitude of the reference point
'longitude' => -74.0060, // Longitude of the reference point
'value' => 50, // Maximum distance in kilometers
'compare' => '<', // Comparison operator for distance
),
);
$query = new WP_Query($args);
In this example, lp__distance filters posts to return only those within 50 kilometers of the provided latitude/longitude coordinates.
Result
| The SQL query will be dynamically modified to retrieve posts that meet the specified geographic conditions, making it easy to display location-specific content. |