Skip Navigation

[Resolved] Geo post-relationship using "nearest" parent post, and copy custom fields values

This support ticket is created 6 years, 9 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#628732

Hi all, I would like to know if it is possible to establish an automatic post-relationship using geographic proximity.
I have one or more CPT with geolocation and an additional specific custom fields.
I want the user to be able to add another type of children CPT that has all the needed custom fields (hidden to the user), and this CPT inherits values automatically from the nearest existing CPTs.
For example, I have a serie of locations with property A and another serie with property B.
The user adds a CPT that must have values A and B.
The nearest point A will give to the CPT its values for A.
The nearest point B will give to the CPT its values for B.
Is this possible?
Kindest regards

Lorenzo

#628954

There are a few challenges here, and one ticket is probably not enough to address all of these. A significant amount of custom code is required. Here is the general idea:

1. Parent / child relationships cannot work both ways. In other words, it is not possible for CPT type A to be a parent of CPT type B, and also for CPT type A to be a child of CPT type B. So let's say you have two post types that will be included in the distance filter View, "Trucks" and "Boats". If you add a new Truck using CRED, then you could select a parent Boat. But if you add a Boat using CRED, you could not select a parent Truck, because this type of parent / child relationship is not supported. I'm not sure if that's something you had considered yet.

2. There isn't a quick way to find the closest post while you are creating or editing a post with CRED. The only way I can think of to do this is to create another View of the CPTs, filtered by distance based on the address custom field in the new post created by CRED, and limit the number of results to 1. Place that View somewhere on the new CPT post, and it will show you the closest post.

3. Once you know the closest post, you can set up a CRED form to edit the child post. Set the parent post ID value in the parent select field, and include a submit button in the form. It can say something like "Connect to parent". When the CRED form is submitted, the child CPT will be related to the parent CPT.

4. Set up a cred_save_data hook that will copy the custom field values from the parent post into the child post. I can provide some examples of this if you'd like.

If this sounds like something you might be capable of pursuing, feel free to open individual tickets to discuss a specific part of the process.

#629056

Hi thank you very much for your answer that helped me to focus some aspects.
1 - I relized I don´t need to inherit the values, but it is enough to display the values of the nearest CPT in the post pages.
2 - according to point 1, maybe I don´t need a relationship, everything can be managed only using proximity, I am evaluating to change the CPT organization so they can be just two categories (I hope I can hide a category to the users)
3 - considering 1 and 2, the user doesn´t need to interact with my values, the valued just have to be displayed on the page using the filter you suggested

So good progress on my side, thanks a lot, it´s not a coding progress but a better understanding of my needs.
I am coming to a better idea of how to organize the data, that is a core aspect both for performance and results.
Thanks again!

#629139

I'm sorry, I just realized that I gave you some information that isn't quite accurate. It turns out that the sort-by-distance feature is planned for release in Toolset Maps 1.5, and is not implemented in the current version of Maps. Right now you have the ability to return a list of results within a specified radius, but those results are sorted according to other criteria like post title or another custom field value. I apologize for the misinformation here.