Skip Navigation

[Resolved] Create an address field from individual fields

This support ticket is created 4 years, 5 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by martinB-16 4 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1672637

I would like to compile the address field for Google Maps from individual fields. Example:
Street + ZIP + city + country = toolset address field
How can I do that?

#1673211

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean that you have Street + ZIP + city + country setup as custom fields and on frontend based on those fields you want to display the map marker on the map based on the custom field values Street + ZIP + city + country that makes a singe address value.
-- if above is true:
I would like to know how you setup the map? Are you using blocks or classic views?

#1673987

Hello,
I want to use this in individual posts. The post is designed with blocks.
I also want to use it in a view (multiple posts)

#1674335

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As i understand, you are trying to display the map on individual posts designed with blocks as well as you want to display map on view where you display multiple posts.

If above is true:
- You need to create a content template or view that displays the map in classic mode as using Map block do not support adding multiple dynamic field.

For example - you can add the map marker and adjust its address value using your multiple custom field shortcodes.

[wpv-map-marker map_id='map-2' marker_id='marker-[wpv-post-id]' address="[types field='field-1'][/types] [types field='field-2'][/types][types field='field-'][/types]"][/wpv-map-marker]

Where:
- You can adjust the value of correct map ID, and address attribute value with your original custom field names.

If you do not know how to do it, Please send me access details and problem URL where you want to display the map and I would be happy to assist you further.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1675619

Thanks, the shortcode works.
However, I still have the problem in blocks and views.
Is it not possible to fill the field "wpcf-adress" with the values from the individual fields when saving a post?
Something like this: Set 'wpcf-adresse' = "field1 +" field2 "+" field3 "

#1675983

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

When you say saving the post - do you mean when saving the post from backend or from frontend using Toolset form?

#1676339

Frontend

#1676343

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - if you are using Toolset form then you can use the Toolset form hook: cred_save_data

For example:
- Add the following code to your current theme's function.php file
or
To "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action('cred_save_data','func_update_address_custom_field_value',10,2);
function func_update_address_custom_field_value($post_id,$form_data) {

    if ($form_data['id']==9999) {

        $street = get_post_meta($post_id, 'wpcf-street', true);
        $zip = get_post_meta($post_id, 'wpcf-zip', true);
       $city= get_post_meta($post_id, 'wpcf-city', true);
        $county = get_post_meta($post_id, 'wpcf-county', true);

       $address = $street." ".$zip." ".$city." ".$county ;

        update_post_meta($post_id, 'wpcf-address', $address);
       
    }
}

Where:
- Replace 9999 with your original form ID
- please adjust field slugs where required

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1679707

I understood and incorporated the principle of the custom code. I have adjusted the field names and the ID. However, it doesn't work.
Do I have to add a shortcode to the form?

#1679941

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is strange. Can you please share problem URL where I can see the form where you fill the information as well as tell me where exactly the code I shared you added.

In addition to that, I will require access details in order to check whats going wrong with your site:

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1681883

I am currently unable to do so. Therefore, the ticket can be closed first. I will reactivate it if necessary.