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.
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.
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.
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?
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.