Skip Navigation

[Resolved] Can I delete a post with an action triggered by the post itself?

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 4 replies, has 2 voices.

Last updated by himanshuS 1 year, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2530301

Context -
I am creating a temp job post to act as a dummy while I call the real job post using generic field and make changes to it.

This happens because the temp job form has two purposes:
1) It can be used to create new job post if one does not exist, and does the rest of the processing.
2) It acts a temp job post, if the job post exists and then does the processing.

Now, all is well is option (1). But, in option (2), I am using the previous job post to do stuff and redirect the user to a custom page. However, in the end, I am left with a temp post.

Can I delete this temp post with a hook (may be the redirect hook as it is the last one in use with a later priority number)? This way all the work I need to do will be done and in the very end the temp post will be deleted.

Can that work or are there limitations on deleting a post that calls the action?

#2530881

Hello,

Is there any relationship between the temp job post and real job post?

How do you redirect user to the "custom page"?
If you redirect user after submit a Toolset post form, you can try the action hook "cred_success_redirect":
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
use it to trigger a custom PHP function, get the related "temp post", and delete it:
https://developer.wordpress.org/reference/functions/wp_delete_post/

#2531147

There is no relationship between the temp job post and the real job post.

It is just used as a vessel to process for primary job. The redirect happens with cred_success_redirect.

can I use two different redirects with different priority :
priority 10 - direct to new page
priority 20 - delete the temp post.

#2531589

Yes, you can use different priority parameters to trigger different custom PHP function, all those PHP function will be excuted.

#2531599

My issue is resolved now. Thank you!