Home › Forums › ACF PRO › Default marker for maps › Reply To: Default marker for maps
Hi Doug,
You can achieve it by using the acf/save_post hook and the update_field() function like this:
function my_acf_default_map( $post_id ) {
$selector = 'google_map_field_name';
// get new value
$value = get_field($selector, $post_id);
if( !$value ){
$value = array(
"address" => "218 Abeckett St, Melbourne VIC 3000, Australia",
"lat" => "-37.81025862543725",
"lng" => "144.95670318603516"
);
update_field($selector, $value, $post_id);
}
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_default_map', 20);
But if you only need the address, which is basically a text, then you can always use the text field and set the default value on the backend instead.
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.