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

---

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

## In this article

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

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

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

### 󠀁[See also](https://developer.wordpress.org/reference/hooks/before_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/before_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/before_delete_post/?output_format=md#more-information)󠁿

This hook runs:

 * Just before other data associated with the post is deleted – like meta data. 
   After the other data is deleted, the _delete\_post_ action executes, the primary
   post is removed, and then the _deleted\_post_ action is executed.
 * When items marked for trash are going through final (forced) deletion (e.g. the
   trash is disabled and an item is deleted).

This hook does not run:

 * For posts that are being marked as trash (unforced). The _wp\_trash\_post_ hook
   is the functional equivalent, executed just before items are marked as trash.
 * For attachments. The _delete\_attachment_ hook is the functional equivalent, 
   executed just before posts of type attachment are processed. With attachments,
   exactly as with other post types, meta data is removed, the _delete\_post_ action
   is run, then the attachment is removed from the database, and finally, the _deleted\
   _post_ action is run.

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

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

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/before_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/before_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/before_delete_post/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/hooks/before_delete_post/?output_format=md#comment-content-4859)
 2.    [ahsynv](https://profiles.wordpress.org/ahsynv/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/before_delete_post/#comment-4859)
 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%2Fbefore_delete_post%2F%23comment-4859)
     Vote results for this note: 4[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%2Fbefore_delete_post%2F%23comment-4859)
 4.      ```php
         <?php
         add_action( 'before_delete_post', 'wpdocs_my_func', 99, 2 );
         function wpdocs_my_func( $postid, $post ) {
     
             if ( 'wpdocs_my_custom_post_type' !== $post->post_type ) {
                 return;
             }
     
             // My custom stuff for deleting my custom post type here
         }
         ?>
         ```
     
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fbefore_delete_post%2F%3Freplytocom%3D4859%23feedback-editor-4859)
 6.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/before_delete_post/?output_format=md#comment-content-4338)
 7.    [Collins Mbaka](https://profiles.wordpress.org/collinsmbaka/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/before_delete_post/#comment-4338)
 8.  [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%2Fbefore_delete_post%2F%23comment-4338)
     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%2Fbefore_delete_post%2F%23comment-4338)
 9.  Let’s suppose you have a plugin and when a certain post_type is deleted you want
     to perform some action.
 10.     ```php
         <?php
         add_action( 'before_delete_post', 'wpdocs_my_func' );
         function wpdocs_my_func( $postid ) {
     
             // We check if the global post type isn't ours and just return
             global $post_type;   
     
             if ( 'wpdocs_my_custom_post_type' !== $post_type ) {
                 return;
             }
     
             // My custom stuff for deleting my custom post type here
         }
         ?>
         ```
     
 11.  * It would be a good practice not to use global variables when the needed information
        is available in parameters because global variables can easily be broken by
        different context, plugins or updates.
      * [Teemu Suoranta](https://profiles.wordpress.org/teemusuoranta/) [5 years ago](https://developer.wordpress.org/reference/hooks/before_delete_post/#comment-5697)
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fbefore_delete_post%2F%3Freplytocom%3D4338%23feedback-editor-4338)

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