Fires after a post is deleted, at the conclusion of wp_delete_post() .
Description
See also
Parameters
$post_id
int- Post ID.
$post
WP_Post- Post object.
Source
do_action( 'after_delete_post', $post_id, $post );
Fires after a post is deleted, at the conclusion of wp_delete_post() .
$post_id
int$post
WP_Postdo_action( 'after_delete_post', $post_id, $post );
You must log in before being able to contribute a note or feedback.
Perform some action when a post is deleted –
Performing Actions After Deleting a Post Based on Multiple Conditions
In this tutorial, you will learn how to execute custom code after a WordPress post is deleted, but only under specific conditions. We will use a combination of post type, post status, and custom field value checks to determine whether to run the custom code.
Step 1: Hook into the
after_delete_post
ActionFirst, we need to hook into the
after_delete_post
action, which fires after a post is deleted. Add the following code to your theme’sfunctions.php
file or your custom plugin file:Step 2: Define the
wpdocs_do_something
Function