WP-Locate-It WordPress Plugin
So, What Does WP-Locate-It do?
WP-Locate-It is geared towards WordPress developers to allow location information to be saved as post meta data. It is a lightweight and easy to use tool-set that utilizes the power of the Google Maps API in order generate location data for standard and custom post types.
How Do I Start Using It?
Once you enable the plugin, you simply go to “Settings > WP-Locate-It” and check which post types you would like to use it with. Location fields will then be available when you are creating or editing a WP-Locate-It enabled post type. You simply type in the address in the search bar and select the location that pops up. The fields will automatically be filled out once an address is selected.
What Can I Do With the Location Meta Data?
Once you have the location data saved to your post, there’s actually quite a bit that you can do with it by utilizing the power of WP_Query! The plugin adds in the “proximity” query variable, which is an array containing information. The “proximity” variable works like so:
$proximity = array( 'latitude' => '40.7444051', 'longitude' => '-73.98715549', 'distance' => '30', 'units' => 'mi' );
So, with using the sample data above we could use it inside of a WP_Query object, like so:
$query = new WP_Query( array( 'post_type' => 'location', 'proximity' => array( 'latitude' => '40.7444051', 'longitude' => '-73.98715549', 'distance' => '30', 'unit' => 'mi' ); ));
The example query above will find all custom post types named “location” that are within a 30 mile radius of the given latitude and longitude and automatically order them by nearest location.
Proximity Data Requirements
The only requirements in order to query by proximity are latitude and longitude. Distance is not required, and if not provided it will pull all locations (within the posts per page limit) sorted by closest distance first. The unit of measure, if not specified, defaults to miles. Supported unit of measures are miles (mi), kilometers (km), meters (m), yards (y), feet (ft), inches (in), and centimeters (cm).
Meta Field Names
|Zip Code Suffix||_zip_suffix|
Available Action Hooks
|wp_locate_it_before_address_finder||Gets called right before location finder input is loaded in WordPress admin.||$post|
|wp_locate_it_before_fields||Gets called right before the meta fields are displayed in WordPress admin.||$post|
|wp_locate_it_after_fields||Gets called right after the meta fields are displayed in WordPress admin.||$post|
Available Filter Hooks
Check it out at https://github.com/lenbradley/wp-locate-it