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

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#user-contributed-notes)

Fires immediately before a post is deleted from the database.

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

 `$post_id`int

Post ID.

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

Post object.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#more-information)󠁿

Take note, by the time the hook triggers, the post **comments and metadata** would
have **already been deleted**. Use the [before_delete_post](https://developer.wordpress.org/reference/hooks/before_delete_post/)
hook to catch post deletion before that.

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

    ```php
    do_action( '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#L3967)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/post.php#L3967-L3967)

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

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

Trashes or deletes an attachment.

  | 
| [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/delete_post/?output_format=md#changelog)󠁿

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

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

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/delete_post/?output_format=md#comment-content-4052)
 2.   [Collins Mbaka](https://profiles.wordpress.org/collinsmbaka/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/delete_post/#comment-4052)
 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%2Fdelete_post%2F%23comment-4052)
    Vote results for this note: 1[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%2Fdelete_post%2F%23comment-4052)
 4. Let’s suppose you have a plugin that, for one reason or another, stores its own
    post metadata in a separate database table called codex_postmeta. One of the ways
    you can achieve synchronization is to be made aware when a post is deleted so that
    you can replicate the changes yourself.
 5.     ```php
        add_action( 'admin_init', 'wpdocs_codex_init' );
        function wpdocs_codex_init() {
            add_action( 'delete_post', 'wpdocs_codex_sync', 10 );
        }
    
        function wpdocs_codex_sync( $pid ) {
            global $wpdb;
            $query = $wpdb->prepare( 'SELECT post_id FROM codex_postmeta WHERE post_id = %d', $pid );
            $var = $wpdb->get_var( $query );
            if ( $var ) {
                $query2 = $wpdb->prepare( 'DELETE FROM codex_postmeta WHERE post_id = %d', $pid );
                $wpdb->query( $query2 );
            }
        }
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fdelete_post%2F%3Freplytocom%3D4052%23feedback-editor-4052)

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