Skip Navigation

[Resolved] Perform action before post delete

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/Karachi (GMT+05:00)

This topic contains 3 replies, has 3 voices.

Last updated by Waqar 1 year, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2638343

Tell us what you are trying to do?

I need to execute a php function after a post delete button has been clicked, but before the deletion fires. There is a custom field value I need to capture and update a different post with.

Are there any hooks/actions that would allow me to do this?

Is there any documentation that you are following?

https://toolset.com/forums/topic/action-hook-fired-before-post-will-be-deleted/

This is similar, but the delete button will be on the post content template, not on a form. So I'm unsure how I would target the deletion action, as this appears to target the form submission action.

#2638351

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Would the WordPress before_delete_post hook work for you?

https://developer.wordpress.org/reference/hooks/before_delete_post/

Otherwise, can you clarify exactly how you are adding the delete button to your template so we know we are targeting the right thing.

#2638359

Thanks Nigel, not sure how I missed that, yes I believe that will work.

I was planning on using the cred_delete_post_link shortcode on the content template. For this use case I will need to target two different post types, containers and shipments.

#2638517

Hi,

Thanks for writing back.

Feel free to try the 'before_delete_post hook' and let us know if you have any follow-up question.

For a new question or concern, you're welcome to start a new ticket.

regards,
Waqar