Skip Navigation

[Resuelto] Converting street, city, state, zipcode fields to an address field for Maps

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

We built partner records with separate single line text fields for street, city, state and zipcode (in repeating field groups for multiple locations per partner). We also have latitude and longitude fields for each location that represent the center of the zipcode but not sure we need those going forward.

We now want to use Toolset Maps to find and sort partners by distance. We don't necessarily need to show them on a map but may want to.

Can I just run an update query that adds a wpcf-partner-address postmeta row for each partner and assembles a # street, city, state zip code string to place in there from the separate existing fields?

Solution:

There isn't existed "update query" to achieve what you want, it needs custom codes.

And if there aren't too much record, you can just update the address field value manually.

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/functions/#address

This support ticket is created hace 6 años, 2 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por scottL-3 hace 6 años, 2 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#1109621

Tell us what you are trying to do?
We built partner records with separate single line text fields for street, city, state and zipcode (in repeating field groups for multiple locations per partner). We also have latitude and longitude fields for each location that represent the center of the zipcode but not sure we need those going forward.

We now want to use Toolset Maps to find and sort partners by distance. We don't necessarily need to show them on a map but may want to.

Can I just run an update query that adds a wpcf-partner-address postmeta row for each partner and assembles a # street, city, state zipcode string to place in there from the separate existing fields?

For partners with more than one location, do I have to also add the _wpcf-partner-address-sort-order row and build the json array properly? (and does this array need to exist if there is only one location?)

Is there any documentation that you are following?
Not that I can find.

Is there a similar example that we can see?
Not that I know of.

What is the link to your site?
enlace oculto but you can't really use the front-end to understand this issue.

#1110352

Hello,

Q1) Can I just run an update query that adds a wpcf-partner-address postmeta row for each partner and assembles a # street, city, state zipcode string to place in there from the separate existing fields?

There isn't existed "update query" to achieve what you want, it needs custom codes, you might consider our experienced contractors:
https://toolset.com/contractors/

And if there aren't too much record, you can just update the address field value manually.

Q2) For partners with more than one location, do I have to also add the _wpcf-partner-address-sort-order row and build the json array properly? (and does this array need to exist if there is only one location?)
What kind of "json array" do you need?
If you are going to order the result by the specific value, then the custom field "wpcf-partner-address-sort-order" is needed.

#1110522

Hi Luo Yang, I AM one of the Toolset experienced contractors. There is nothing documented anywhere that would tell an experienced contractor what is needed to do this conversion. I assume by custom programming you mean using the Toolset API with PHP to add the address field because then Maps, Types and Views will do what they need to do to take care of the caching of lat / lng, adding the sort order, etc. If so I can do that instead of use a query to do it. Can you just confirm this is what you meant by custom code?

Also, once this is done, can I access the cached lat / lng for each address easily from PHP?

#1111266

I mean there isn't existed "update query" to achieve what you want, so you can consider custom codes.

And you are right, there isn't document for the Toolset map API:
https://toolset.com/documentation/programmer-reference/

If you agree, we can take it as a feature request of documentation.

For those new questions:
q1) I assume by custom programming you mean using the Toolset API with PHP to add the address field because then Maps, Types and Views will do what they need to do to take care of the caching of lat / lng, adding the sort order, etc. If so I can do that instead of use a query to do it. Can you just confirm this is what you meant by custom code?
Yes, if you are using Toolset API to setup the custom address field value, Maps, Types and Views will do what they need to do to take care of the caching of lat / lng

What kind of sort order do you want to achieve? are we talking about a number field "wpcf-partner-address-sort-order" for each location post?

Q2) Also, once this is done, can I access the cached lat / lng for each address easily from PHP
Yes, you can access the address field value with PHP codes, see our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/#address
click the link "Repeater attributes, User attributes, Term attributes, Usage examples", you should be able to see the PHP examples for address field.

#1113588

Thanks Luo. I wrote a small PHP script that took all the info from my separate locations fields and concatenated it into address strings. Added those to a new address field on the partner records and created new partner records as children of the first location for partner that had more than one location. All seem to work properly with the map and the distance search now.