Skip Navigation

[Closed] Update CF of parent CPT after child cred form submitted

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.

Our next available supporter will start replying to tickets in about 7.93 hours from now. Thank you for your understanding.

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)

This topic contains 8 replies, has 2 voices.

Last updated by Luo Yang 1 year, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2530495

Tell us what you are trying to do?
I have a cred form that upon it being submitted and based on a value of a CF I want to update the CF of it's parent.

For example I have:
One to many Box < Customers

Customer CPT that includes a status CF (active, waiting, expired).
Box CPT that includes a status CF (available, rented)

Depending on the value of this CF when the customer form is submitted I want it to update the value of a status of it's parent CF.
e.g. Active = Rented, Waiting = Available, Expired = Available.

I'm sure this is possible with a custom function and would appreciate your kind assistance.

Is there a similar example that we can see?
https://toolset.com/documentation/programmer-reference/cred-api/
https://toolset.com/forums/topic/passing-a-value-from-a-cred-form-to-another-field/

Thank you!

#2530783

Hello,

Since you are using one-to-many relationship, I assume you are going to:
After user submit the child post form for creating new "Customers" post, check all related(brother) posts, if any of them is in "active" status, then update the parent "Box" post status to: Available
and so on.

Can you confirm it first?

#2530887

Hi Luo, thank you for getting back to me.
Yes that's basically it but for editing a customer too because their status maybe set as expired (manually) in which case the box status changes back to available.

The only other approach to this was to remove status CF from box completely and use the customer status to find boxes that are available or rented. The problem with this is that I could never find the number for available. but I could get rented and total boxes. I wondered if calculating difference between item counts could work e.g. total boxes view count - customer boxes active view count but it looks like this is only possible with CF not counts. After reading various support posts I concluded the top solution was actually more workable.

Thank you.

#2531231

"Check all related(brother) posts, if any of them is in "active" status, then update the parent "Box" post status to: Available."
Check all related(brother) posts, if any of them is in "active" status, then update the parent "Box" post status to: Rented

A box-status is 'rented' if any of it's child customer-status is 'active'.
A box-status is 'available' if it has no customer-status as 'active'.
A box can have multiple child customers- status as 'expired' or 'waiting' and the box-status will be 'available'.

#2531585

It needs custom codes, in order to test and debug the custom PHP codes, I need a live website to test and debug.
How do you setup the post types and custom fields?
Can you reproduce the same problem in below test site?
hidden link

#2531769

Thank you Luo,
I've recreated the issue on the test site now with a few notes - hidden link

#2532745

Thanks for the details, I am checking it in the test site, will update here if find anything

#2535277

Just wondering if there's an update on this.. On the surface it seems Toolset is great for building this type of site but all this coding required seems overkill for something that seems so obvious. I wonder if there's another way around this which avoids so much custom coding? Thanks

#2535287

I have checked the test site settings,
You are using three custom post types:
- Lockers
- Locker Locations
- Customers

Three pos type relationships:
- One-to-many relationship between "Locker Locations" and "Customers"
- One-to-many relationship between "Locker Locations" and "Lockers"
- One-to-many relationship between "Lockers" and "Customers"

Three post field groups:
- "Lockers" post field group:
Locker Status: Available | Rented
- "Customer" post field group:
Status: Active | Waiting | Expired
- "Locker Locations" post field group

And there isn't any post form in the test site.

It is different settings from this thread, to avoid more misunderstandings, in order to setup the custom codes for you, please confirm this:
You are going to do these:
When user edit/create a "Customer" post, update the parent "Lockers" post field "Locker Status" value by all related "Customer" posts field "status" value.

The topic ‘[Closed] Update CF of parent CPT after child cred form submitted’ is closed to new replies.