Frontend Submission - Google Maps - Custom Binding
Support › MB Frontend Submission › Frontend Submission - Google Maps - Custom Binding
- This topic has 6 replies, 2 voices, and was last updated 3 days, 11 hours ago by
Codog.
-
AuthorPosts
-
June 27, 2024 at 8:52 PM #45746
Codog
ParticipantHi there,
I have a frontend submission form that contains a Google Map and address field that uses the Geocoding API for autocomplete. All works as expected!However, I don't seem to be able to get the "Custom Binding" working as documented here
Here is my code with an attempt to bind the 'City' & 'Country' to a hidden custom field:
// Map field. [ 'id' => 'location_map', 'type' => 'map', 'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'std' => '51.5074,-0.1278,15', 'address_field' => 'location_address', ], // Address field. [ 'id' => 'location_address', 'name' => __( 'Address', 'text-domain' ), 'type' => 'text', 'placeholder' => 'Enter address...', 'desc' => __( 'Enter the complete address.', 'text-domain' ), 'required' => true, ], // Hidden field to store the city and country [ 'id' => 'city_country', 'type' => 'hidden', 'binding' => 'city + " " + country', 'std' => 'null', ],
Expected result: Autocomplete - City and Country values to be added to hidden field.
Actual result: Returns nothing?I have also tried this with a plain text field and the result is the same?
What am I missing?
Thanks in advance 🙂
June 27, 2024 at 10:49 PM #45752Peter
ModeratorHello,
Do you add the setting
geo
to the field group settings? Please follow the documentation https://docs.metabox.io/extensions/meta-box-geolocation/#field-group-settingsJune 27, 2024 at 11:01 PM #45753Codog
ParticipantHi Peter, thanks for the response. Yeah this was the bit I was unclear about? I assume you mean adding this:
'geo' => [ 'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxx', ],
To some field group? Do you mean I need to wrap my "Map Field, Address Field , Hidden field" in a "Field Group and add the above? Not clear to me?
As I am strictly doing this with code I would be grateful if you could show me a simple example?
June 28, 2024 at 10:05 PM #45761Peter
ModeratorHello,
If you use the code to register the meta box (field group in the builder UI), you need to add
geo
to the meta box settings. For example:add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Event details', 'post_types' => 'event', 'geo' => [ 'api_key' => 'YOUR API KEY', ], 'fields' => [ ... ], ]; return $meta_boxes; } );
May 14, 2025 at 1:25 AM #48251Codog
ParticipantHi there,
I never got this working. I have re-visited your suggestion (from above):add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Event details', 'post_types' => 'event', 'geo' => [ 'api_key' => 'YOUR API KEY', ], 'fields' => [ ... ], ]; return $meta_boxes; } );
But this binding never seems to work for me?
1. I have set up an unrestricted API key with all available API's.
2. I have added the geo parameter to my Metabox (Exactly as suggested):
3. My full test implementation is like this:add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Event details', 'post_types' => 'event', 'geo' => [ 'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',// Unrestricted API Key ], 'fields' => [ // Map field. [ 'id' => 'location_map', 'type' => 'map', 'api_key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'std' => '51.5074,-0.1278,15', 'address_field' => 'location_address', ], // Address field. [ 'id' => 'location_address', 'name' => __( 'Address', 'text-domain' ), 'type' => 'text', 'placeholder' => 'Enter address...', 'desc' => __( 'Enter the complete address.', 'text-domain' ), 'required' => true, ], // Hidden field to store the city and country [ 'id' => 'city_country', 'type' => 'hidden', 'binding' => 'city + " " + country', 'std' => 'null', ], ], ]; return $meta_boxes; } );
I am using a clean install of WP:
- WP 6.8.1
- Metabox Version 5.10.9
- AIO Version 2.1.1
- PHP 8.3
- MYSQL 8.0.35I have the MB Geolocation extension on.
I see no console log errors.
I see no debug.log errors.Can you confirm that this implementation works for you? (or Not). I cannot get this feature to work for love or money?
Thanks.
May 14, 2025 at 9:59 PM #48255Peter
ModeratorHello,
It works properly on my demo site. Please note that the
city
field is not supported when using Google Maps. You should uselocality
instead ofcity
. Following the documentation https://docs.metabox.io/extensions/meta-box-geolocation/#other-fields
And check my screen record https://drive.google.com/file/d/1dZqoujJ89l3wUoPsHU_p5f4f6jl4faQA/view?usp=sharingMay 14, 2025 at 10:48 PM #48258Codog
ParticipantThanks for the clarification Peter!
That was really helpful 🙂
I will try this myself.
-
AuthorPosts
- You must be logged in to reply to this topic.