Title: wp_trash_post
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_trash_post( int $post_id ): 󠀁[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)󠁿|false|null

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#wp--skip-link--target)

Moves a post or page to the Trash

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

If Trash is disabled, the post or page is permanently deleted.

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

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

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

 `$post_id`intoptional

Post ID. Default is the ID of the global `$post` if `EMPTY_TRASH_DAYS` equals true.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#return)󠁿

 [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|false|null
Post data on success, false or null on failure.

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

    ```php
    function wp_trash_post( $post_id = 0 ) {
    	if ( ! EMPTY_TRASH_DAYS ) {
    		return wp_delete_post( $post_id, true );
    	}

    	$post = get_post( $post_id );

    	if ( ! $post ) {
    		return $post;
    	}

    	if ( 'trash' === $post->post_status ) {
    		return false;
    	}

    	$previous_status = $post->post_status;

    	/**
    	 * Filters whether a post trashing should take place.
    	 *
    	 * @since 4.9.0
    	 * @since 6.3.0 Added the `$previous_status` parameter.
    	 *
    	 * @param bool|null $trash           Whether to go forward with trashing.
    	 * @param WP_Post   $post            Post object.
    	 * @param string    $previous_status The status of the post about to be trashed.
    	 */
    	$check = apply_filters( 'pre_trash_post', null, $post, $previous_status );

    	if ( null !== $check ) {
    		return $check;
    	}

    	/**
    	 * Fires before a post is sent to the Trash.
    	 *
    	 * @since 3.3.0
    	 * @since 6.3.0 Added the `$previous_status` parameter.
    	 *
    	 * @param int    $post_id         Post ID.
    	 * @param string $previous_status The status of the post about to be trashed.
    	 */
    	do_action( 'wp_trash_post', $post_id, $previous_status );

    	add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status );
    	add_post_meta( $post_id, '_wp_trash_meta_time', time() );

    	$post_updated = wp_update_post(
    		array(
    			'ID'          => $post_id,
    			'post_status' => 'trash',
    		)
    	);

    	if ( ! $post_updated ) {
    		return false;
    	}

    	wp_trash_post_comments( $post_id );

    	/**
    	 * Fires after a post is sent to the Trash.
    	 *
    	 * @since 2.9.0
    	 * @since 6.3.0 Added the `$previous_status` parameter.
    	 *
    	 * @param int    $post_id         Post ID.
    	 * @param string $previous_status The status of the post at the point where it was trashed.
    	 */
    	do_action( 'trashed_post', $post_id, $previous_status );

    	return $post;
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#hooks)󠁿

 [apply_filters( ‘pre_trash_post’, bool|null $trash, WP_Post $post, string $previous_status )](https://developer.wordpress.org/reference/hooks/pre_trash_post/)

Filters whether a post trashing should take place.

 [do_action( ‘trashed_post’, int $post_id, string $previous_status )](https://developer.wordpress.org/reference/hooks/trashed_post/)

Fires after a post is sent to the Trash.

 [do_action( ‘wp_trash_post’, int $post_id, string $previous_status )](https://developer.wordpress.org/reference/hooks/wp_trash_post/)

Fires before a post is sent to the Trash.

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

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

Updates a post with new post data.

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

Trashes or deletes a post or page.

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

Moves comments for a post to the Trash.

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

Adds a meta field to the given post.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

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

Retrieves post data given a post ID or post object.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#)

| Used by | Description | 
| [WP_REST_Templates_Controller::delete_item()](https://developer.wordpress.org/reference/classes/wp_rest_templates_controller/delete_item/)`wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php` |

Deletes a single template.

  | 
| [_wp_keep_alive_customize_changeset_dependent_auto_drafts()](https://developer.wordpress.org/reference/functions/_wp_keep_alive_customize_changeset_dependent_auto_drafts/)`wp-includes/theme.php` |

Makes sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection.

  | 
| [_wp_delete_customize_changeset_dependent_auto_drafts()](https://developer.wordpress.org/reference/functions/_wp_delete_customize_changeset_dependent_auto_drafts/)`wp-includes/nav-menu.php` |

Deletes auto-draft posts associated with the supplied changeset.

  | 
| [WP_REST_Posts_Controller::delete_item()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/delete_item/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Deletes a single post.

  | 
| [wp_ajax_trash_post()](https://developer.wordpress.org/reference/functions/wp_ajax_trash_post/)`wp-admin/includes/ajax-actions.php` |

Handles sending a post to the Trash via AJAX.

  | 
| [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.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#)

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

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

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

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_trash_post/?output_format=md#comment-content-1247)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_trash_post/#comment-1247)
 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%2Ffunctions%2Fwp_trash_post%2F%23comment-1247)
    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%2Ffunctions%2Fwp_trash_post%2F%23comment-1247)
 4. **Basic Example**
 5. Trash the default WordPress Post, “Hello World,” which has an ID of ‘1’.
 6.     ```php
        <?php wp_trash_post( $post_id = 1 ); ?>
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_trash_post%2F%3Freplytocom%3D1247%23feedback-editor-1247)

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