Skip Navigation

[Resolved] How to know if a taxonomy is edited while using CRED hook for custom behavior

This support ticket is created 2 years, 3 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
- 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 2 replies, has 2 voices.

Last updated by himanshuS 2 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#2450199

I have edit project form where project is the CPT and has a taxonomy called skills.
The edit form has lot of edits including the taxonomy field.
I want to have no custom effect if the taxonomy fields are not changed.
But, if the taxonomy fields are updated in the edit form, I want to trigger some custom code by using cred_save_data.

Now, my understanding is that at cred_save_data, the field is already changed so I won't have the original data available.

Which hook can I use to compare the current taxonomy and new taxonomy to trigger different code if there is an edit.
A few questions
1. Is it cred_before_save_data?
2. If yes, how do I get the post ID to get the original data and how to do I get the newly selected data. Is it using $_POST['my_custom_field'] format?
3. What happens if it is a multi select taxonomy? How do I get value for all selected fields?

#2450861

Hello,

1) Yes, you can try with cred_before_save_data action hook.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data
This hook allows doing a custom action right before saving or processing any data but after validation

2) Yes, you can get the post ID by variable $_POST['_cred_cred_prefix_post_id'], and use it to get other information of original post.

3) You can get the new user input values, for example WordPress Built-in category:
$_POST['category']

#2454597

My issue is resolved now. Thank you!