Hi,
I would to know how to set a calculated value for a Custom Field when saving a Custom Type Post.
I give you and example.
I've a "mysite_users" is the Custom Type Post.
The "mysite_users" has this Custom Fields:
- Name : is a text field
- Type : is a Select field with values Gold - Silver - Bronze
- Date Subscription : is a Date field
- Date Expiration : is a Date field but with automatic value based on Type field
(For example:
if type = Gold then Expiration = Date + 12 months
if type = Silver then Expiration = Date + 6 months
if type = Bronze then Expiration = Date + 1 month)
When I add a new "mysite_users" I insert:
Name = "John"
Type = "Gold"
Date Subscription : "06/21/2021"
After saving the system autofill the "Date expiration" with the value "06/21/2022" (= 06/21/2021 + 12Months)
Can you help me? Can you give an example?
Regards
Alex
Hi Alex,
Thank you for contacting us and I'd be happy to assist.
If you're using the front-end Toolset Form to save the custom post type, you can use the "cred_save_data" hook to fire a custom function that can update the Date Expiration field:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
In case, you're saving the custom post types using both, the front-end Toolset Form as well as the admin area post edit screen, then you can alternatively use the "save_post" hook:
https://developer.wordpress.org/reference/hooks/save_post/
You'll find some relevant examples for the similar requirement in these threads:
https://toolset.com/forums/topic/cred-post-form-doesnt-fire-the-save_post-hook/
https://toolset.com/es/forums/topic/calculation-and-storing-in-a-new-field/
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar