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?
hidden link but you can't really use the front-end to understand this issue.
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.
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?
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.
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.