Support

Account

Home Forums ACF PRO Is it possible to programmatically update a google map acf by lat/lang?

Solving

Is it possible to programmatically update a google map acf by lat/lang?

  • Hi, is it possible and how to?

    I need to import a csv full of places into custom post type posts, I’ll do it with wpallimport. And I would need to set the google map acf field for each post based on lat/lang coordinates instead of addresses. Is it possible? Is there any filter od function like set_field(‘mymap’, [lat], [lang])?

  • I mean lat/long, not lat/lang, sorry, it seems I can’t edit the original post.

  • If you are doing this with WP All Import and using the ACF add-on then I would contact WP All Import for advice. I’ve used it but do not have any experience importing to map fields.

  • I think the main question is: does the ACF API have some function to update a map field with lat/long instead of address. Or, what ways does the ACF API give us to update a map field?

  • You are using WP all import, as I said, if you have the ACF extension for this plugin then it will handle the import for you and then there is no need to call any ACF function.

    If you want to do this yourself then update_field() https://www.advancedcustomfields.com/resources/update_field/ would be used, just like any other field. Make sure to read the important notes about using the field key vs. the field name when updating fields that do not exist. The value for using this function would be a value that matches what ACF normally stores in the database. In the case of a GM field it would be an array. Exactly what needs to be in the array I can’t really answer, I’ve never used a GM field or needed to update them if I did. You can figure this out by saving a value to a map field and looking at the value that is stored in the database, or you can run a test on the front end of the site.

    
    echo '<pre>'; print_r(get_field('your-field-name', false, false)); echo '</pre>';
    
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Is it possible to programmatically update a google map acf by lat/lang?’ is closed to new replies.