Skip Navigation

[Resolved] Combining street, suite, city, state and zip fields into Toolset address field

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 5 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#1308373

Tell us what you are trying to do?
I'm trying to create Google maps, but the Address field displays the address in a single string/line on the front end.
I have fields for street, suite, city, state and zip and would like to combine them for use by my address field

Is there any documentation that you are following?
https://toolset.com/forums/topic/combine-custom-fields-into-single-variable/

Is there a similar example that we can see?
Trying to follow example in above link, but I'm obviously missing something..

add_filter('save_post', 'combine_my_fields');
function combine_my_fields($post_id, $post) {
$address = get_post_meta($post_id, 'wpcf-street', true) . ',';
$address = get_post_meta($post_id, 'wpcf-suite-room', true) . ',';
$address .= get_post_meta($post_id, 'wpcf-city', true) . ' ';
$address .= get_post_meta($post_id, 'wpcf-state', true) . ',';
$address .= get_post_meta($post_id, 'wpcf-zip', true);
update_post_meta($post_id, 'wpcf-clinic-or-location', $address);
}

What is the link to your site?
tuality.org
hidden link
hidden link

#1308565

The Toolset Address Field is as it is for the reason to work with services like Google Maps.
Separating ZIP; City, State, and more will not help in querying the addresses and that's why Toolset Address fields use the Google syntax.

It's not possible, at least not without extensive Custom Code, to convert existing single items of an address to a valid Google Address, not only because it just requires code, but also because the address, after crafting, simply might not match with what Google expects.

Of course, you can concatenate infinite values with PHP, like the example of https://toolset.com/forums/topic/combine-custom-fields-into-single-variable/, but that will not help, if we concatenate wrong values, or ion the wrong sequence, correct?
Hence it also won't help to craft a valid Google Address.
For this simply you'll have to use Google services (Toolset Address field is providing this)

If you use simple addresses above might work, but I cannot guarantee that Google will always accept those addresses.
In the case you want to proceed with that, then yes the code is appropriate, it simply takes many fields and concatenates them to one, then updates a new field with this value.

Now related to the issue you mention, I am confused about the requirement.
1. I'm trying to create Google maps, but the Address field displays the address in a single string/line on the front end.
==> A Google Map and the Address field are separate things. You can create a Map, and display on it markers, but you can also display an address, as stored in the field, without a map, in a list for example.
==> Yes, that will be in a single line, as it's an address provided by Google. There is nothing that can be changed about that, unless you create (as you did, it seems) fields for each addresses detail, like street or city.
==> But then you won't be using Toolset Address Fields that can be plotted on a map because they either have a valid Google Address or Lat/long value.
2. I have fields for street, suite, city, state and zip and would like to combine them for use by my address field
==> If you just want to take all those fields values and update another (address field) with it, then this code is the right one:
https://toolset.com/forums/topic/combine-custom-fields-into-single-variable/#post-18211
Note that this is custom code, which does not use Toolset API, so we cannot assist customizations of it.
==> If those new addresses now do not work in the maps, then that's practically expected, as Google will not show locations if not queried by a specific address format.
It's flexible, yes, but still, it can fail "guessing" the right address

If you need to debug that code, you'll need first to know what's "not working".
Is the post not saving, or is there an error, or is it saving but not all data?
Depending on that you will be able to place a var_dump at the given line on your code, and determine if the code receives and returns the right values or not, and accordingly, you can adjust the code.

Finally, you might try to hook your save_post action a bit later, at priority 30 at least, as seen documented here:
https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/
That ensures the code is loaded late enough for Toolset to have done it's own actions on the post.

That is, however, no solution to have a "valid" google address stored in the Toolset Address field.

Please let me know if you need more help.