Support

Account

Home Forums ACF PRO Populate Google Map lng/lat Reply To: Populate Google Map lng/lat

  • Hey Derk…

    You’re pretty close here.. but the object you’ll use to prepopulate the ACF field is the value of the field (for each post), rather than the field itself..

    Perhaps something like below:

    
    function my_acf_import_address( $value, $post_id, $field )
    {
    
        // Only do this if there is not a google_map
        // value already in this post's fields
        if ( empty( $value ) )
        {
    
            // Here I'm assuming the old map function stored
            // the address, lat & lng as post meta & not as custom fields
    
            $address = get_post_meta( $post_id, '_job_location', true );
            $lat = get_post_meta( $post_id, 'geolocation_lat', true );
            $lng = get_post_meta( $post_id, 'geolocation_long', true );
    
            // Now we assign the returned meta values to the
            // value array to be returned
    
            $value['address'] = $address;
            $value['lat'] = $lat;
            $value['lng'] = $lng;
    
        }
    
        return $value;
    
    }
    
    add_filter('acf/load_value/name=google_map', 'my_acf_import_address', 10, 3);
    

    Hope this helps!