this is my first plugin attempt. i was working on a project that needed a radius search feature. i was looking for a plugin that does that but couldn't find exactly what i needed. i have some knowledge in PHP and Wordpress so i was looking around reading and learning how to get this feature done. While learning and getting it to work i was thinking to go ahead and learn how to create my first plugin. So far it seems to work fine. I believe that some of you can find this plugin useful so you are more then welcome to use it and of course to check for any errors. i was trying to make it to work the best it can and to make it secure as well. But as i said, i have some knowledge and this is my first time doing it. for those who like "digging" in a code if you find code that can be improved or be more secure please let me know.
About the plugin:
The plugin let you add address fields to any post type. using google API, every time address is being added to the post it calculates its latitude and longitude and add it to a custom table "wp_places_locator" in database and to custom fields. when one searches your site, he can enters any form of address (city, zip code or full address) and he chooses the distance value. the address is again being converted to lat/long using google API. then, using a custom SQL the plugin calculate the distance between the lat/long user enter to those exist in the database and choose those that within the distance entered.
After installing the plugin there are few setting in the admin page. most important is to enter the post types where you wish the address fields to appear. user must enter a valide address so the post will be published and added to the database. when the post is being updated google checks for the address. if no lat/long returned that means the address is not exist and the post will set as "draft".
You can use the plugin in two ways. search multiple post types. so the user will see drop down menu of different post types or one post type and its categories. no categories for multiple post types.
[wppl] is the shortcode you can add to any page with the attributes below:
1) one or more post type (comma suppurated) - [post_types="directory_listing,incsub_event"]
2) one or more categories - will take into account only if one post type entered [taxonomies="listing_categories"]
3) [show_map="1"] to display google map with markers.
4) [by_driving="1"] display driving distance in addition to radius distance. since the SQL check a radius the distance results will show as a straight line between the points. which means that when we search for direction to the address of the location the distance will be longer. this feature uses another google's function that calculates the driving distance between the address entered and each post in the result. this can make the results page to upload a little slower.
5)[per_page="5"] number of post per page. since this is a custom SQL query the only why i could make pagination work is by sending results via URL.
6)[get_directions="1"] displays a link that opens google map in a new window and show the directions to the location.
7)[map_height="500"] and [map_width="500"]
thats about it. so after you save some posts with address you can add:
[wppl show_map="1" map_height="300" map_width="630" by_driving="1" post_types="directory_listing" taxonomies="listing_category" get_directions="1" per_page="4"]
and change the values as you wish.
this i believe can be very useful. specially for those who using directory or events plugin or for real estate websites.
you can see my demo site here
any comment are more then welcome.