Changeset 2438556
- Timestamp:
- 12/14/2020 12:04:55 AM (5 years ago)
- File:
-
- 1 edited
-
wp-geo-search/trunk/readme.txt (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-geo-search/trunk/readme.txt
r2438554 r2438556 29 29 30 30 31 ` ``31 ` 32 32 $query = new WP_Query(array( 33 33 "geo_query" => array( … … 42 42 ) 43 43 )) 44 ` ``44 ` 45 45 46 46 Optionally, you can then filter by search radius. … … 48 48 By default, distances are given in miles. You can provide `"units" => "km"` if you need kilometres. 49 49 50 ` ``50 ` 51 51 $query = new WP_Query(array( 52 52 "geo_query" => array( … … 56 56 ) 57 57 )) 58 ` ``58 ` 59 59 60 60 Or order by nearness: 61 61 62 ` ``62 ` 63 63 $query = new WP_Query(array( 64 64 "geo_query" => array( … … 68 68 "orderby" => "geo" 69 69 )) 70 ` ``70 ` 71 71 72 72 ### Displaying distance in templates … … 101 101 You could also hook into the `save_post` action to populate meta whenever you create or change a post, by adding a snippet like this to your theme's `functions.php`: 102 102 103 ` ``103 ` 104 104 function example_update_latlngs($post){ 105 105 $location = get_field("location", $post); … … 111 111 112 112 add_action("save_post", "example_update_latlngs", 10, 3); 113 ` ``113 ` 114 114 115 115 This example assumes you are using an [ACF Google Map](https://www.advancedcustomfields.com/resources/google-map/) field called "location", but the data could come from anywhere, including a custom meta box you code yourself, so long as the post meta keys are right. … … 119 119 If you have many posts that you need to add longitude and latitude meta to in bulk, you could add something like this to `functions.php`, which will run on [theme activation](https://developer.wordpress.org/reference/hooks/after_switch_theme/): 120 120 121 ` ``121 ` 122 122 function example_update_all_latlngs(){ 123 123 $query = new WP_Query(array( … … 131 131 132 132 add_action('after_switch_theme', 'example_update_all_latlngs'); 133 ` ``133 ` 134 134 135 135
Note: See TracChangeset
for help on using the changeset viewer.