Forked from mishterk/how-to-update-acf-google-map-field.php
Created
June 27, 2023 18:13
-
-
Save codearachnid/401ae31da5e5e15456cf4120d6aedd8b to your computer and use it in GitHub Desktop.
How to update an ACF Google map field via PHP. This snippet accompanies the article: https://www.awesomeacf.com/snippets/how-to-update-an-acf-google-map-field-programmatically-using-php/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// The field accepts a value with this structure | |
$value = [ | |
'address' => '123 Example St, Townsville XYZ 1234, Country', | |
'lat' => - 38.1486228, | |
'lng' => 144.360414, | |
'zoom' => 14, | |
'place_id' => 'Ei0xMjMgTW9vcmFib29sIFN0LCBHZWVsb25nIFZJQyAzMjIwLCBBdXN0cmFsaWEiMBIuChQKEgmX0JaIHBTUahFyH_LC9sYD8hB7KhQKEglDz-DYDxTUahECZY8QisCjzg', | |
'street_number' => 123, | |
'street_name' => 'Example Street', | |
'street_name_short' => 'Example St', | |
'city' => 'Townsville', | |
'state' => 'Statename', | |
'state_short' => 'XYZ', | |
'post_code' => 1234, | |
'country' => 'Country', | |
'country_short' => 'ZX', | |
]; | |
// If you need a new post, create one. | |
$post_id = wp_insert_post(['post_type' => 'post', 'post_status' => 'publish']); | |
// Update the ACF field for a given post. | |
update_field($field_name, $value, $post_id); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment