Skip Navigation

[Resolved] Order of webhooks

This support ticket is created 3 years, 5 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by donC-3 3 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#2090619

I have customers creating custom post types. I have three different things happen.

1. We validate what they submitted using cred_form_validate
2. on cred_save_data we do some analysis on the post and save it in some custom fields (not toolset created ones though could be moved)
3. on transition_post_status we post to an external api (only on new posts but the logic handles that)

I'm running into an issue where the transition_post_status doesn't have access to the data created on cred_save_data so I assume they happen in a different order. Is there a way to know the order of these hooks?

I was thinking, if it's possible, on the cred_form_validate if I can send back additional data to be saved (not wpcf toolset fields) with the original post save/update that would avoid me needing cred_save_data at all and seems that would then make this all work.

Thoughts?

#2090883

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Don,

Thank you for getting in touch.

The transition_post_status hook isn't one of our Toolset forms hooks. What this means is that it won't have access to the data that is passed from our Forms.

Instead you will need to retrieve the values directly from the database.

I see on the documentation for the hook you it gives you access to the $post object.

You should be able to use the post object and get the post ID like this.

$my_post_id = $post->ID;

From there you should be able to get any of the values that is stored on the post. For example if you need a custom field data you will use the function below.


$field_data = get_post_meta('wpcf-custom-field-slug', $my_post_id);

This should provide you with the post custom field information. Please change the slug "custom-field-slug" to the actual slug of the custom field keeping the wpcf- prefix.

Please let me know if this helps.
Thanks,
Shane

#2090913

Yeah, I was trying to pull direct and wasn't getting it. So just was trying to figure out the order of the events as I was thinking my custom code to inject the fields hadn't run yet.

But simpler (and less work) is can in the validation cred_form_validate we inject additional data fields to be saved? or is it limited to the fields initially sent?

#2090965

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Don,


But simpler (and less work) is can in the validation cred_form_validate we inject additional data fields to be saved? or is it limited to the fields initially sent?

I wouldn't recommend using the cred_form_validate hook for this given that this hook fires after the form has submitted but before the post has been created, so their wouldn't be any post id to lock onto .

What I would recommend is using the cred_save_data hook to do this as it is one of the last hooks to fire after the post has been saved successfully.

Thanks,
Shane

#2090967

Thanks.