Title: after_delete_post
Published: April 25, 2014
Last modified: August 20, 2026

---

# do_action( ‘after_delete_post’, int $post_id, WP_Post $post )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#user-contributed-notes)

Fires after a post is deleted, at the conclusion of [wp_delete_post()](https://developer.wordpress.org/reference/functions/wp_delete_post/).

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#see-also)󠁿

 * [wp_delete_post()](https://developer.wordpress.org/reference/functions/wp_delete_post/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#parameters)󠁿

 `$post_id`int

Post ID.

`$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)

Post object.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#source)󠁿

    ```php
    do_action( 'after_delete_post', $post_id, $post );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/post.php#L4019)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/post.php#L4019-L4019)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_delete_post()](https://developer.wordpress.org/reference/functions/wp_delete_post/)`wp-includes/post.php` |

Trashes or deletes a post or page.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Added the `$post` parameter. | 
| [3.2.0](https://developer.wordpress.org/reference/since/3.2.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#comment-content-6067)
 2.    [Muhammad Ali Akbar](https://profiles.wordpress.org/alireyad/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/after_delete_post/#comment-6067)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fafter_delete_post%2F%23comment-6067)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fafter_delete_post%2F%23comment-6067)
 4.  **Perform some action when a post is deleted – **
 5.      ```php
         add_action( 'after_delete_post', 'aar_do_something', 10, 2 );
         function aar_do_something( $post_id, $post ) {
         	// For a specific post type books
         	if ( 'books' !== $post->post_type ) {
         		return;
         	}
         	// Write your code here
         }
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fafter_delete_post%2F%3Freplytocom%3D6067%23feedback-editor-6067)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/after_delete_post/?output_format=md#comment-content-7120)
 8.    [Noruzzaman](https://profiles.wordpress.org/noruzzaman/)  [  2 years ago  ](https://developer.wordpress.org/reference/hooks/after_delete_post/#comment-7120)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fafter_delete_post%2F%23comment-7120)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fafter_delete_post%2F%23comment-7120)
 10. **Performing Actions After Deleting a Post Based on Multiple Conditions**
 11. 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.
 12. **Step 1: Hook into the `after_delete_post` Action**
 13. First, we need to hook into the `after_delete_post` action, which fires after 
     a post is deleted. Add the following code to your theme’s `functions.php` file
     or your custom plugin file:
 14.     ```php
         add_action( 'after_delete_post', 'wpdocs_do_something', 10, 2 );
         ```
     
 15. **Step 2: Define the `wpdocs_do_something` Function**
 16.     ```php
         function wpdocs_do_something( $post_id, $post ) {
             // Condition 1: Check for specific post types
             $allowed_post_types = array( 'books', 'movies', 'products' );
             if ( ! in_array( $post->post_type, $allowed_post_types ) ) {
                 return;
             }
     
             // Condition 2: Check for specific post statuses (e.g., only if the post was published)
             $allowed_post_statuses = array( 'publish', 'private' );
             if ( ! in_array( get_post_status( $post_id ), $allowed_post_statuses ) ) {
                 return;
             }
     
             // Condition 3: Check for a specific custom field value
             $custom_field_value = get_post_meta( $post_id, 'wpdocs_field_key', true );
             if ( 'specific_value' !== $custom_field_value ) {
                 return;
             }
     
             // Write your code here. All conditions met
             // Example: Log the deletion
             error_log( 'Post with ID ' . $post_id . ' and type ' . $post->post_type . ' has been deleted.' );
     
             // Add your custom code here
             // Example: Remove related data from a custom table
             global $wpdb;
             $wpdb->delete( $wpdb->prefix . 'custom_table', array( 'post_id' => $post_id ) );
         }
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fafter_delete_post%2F%3Freplytocom%3D7120%23feedback-editor-7120)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fafter_delete_post%2F)
before being able to contribute a note or feedback.