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

---

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

## In this article

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

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

Restores a post from the Trash.

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

 `$post_id`intoptional

Post ID. Default is the ID of the global `$post`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_untrash_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_untrash_post/?output_format=md#source)󠁿

    ```php
    function wp_untrash_post( $post_id = 0 ) {
    	$post = get_post( $post_id );

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

    	$post_id = $post->ID;

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

    	$previous_status = get_post_meta( $post_id, '_wp_trash_meta_status', true );

    	/**
    	 * Filters whether a post untrashing should take place.
    	 *
    	 * @since 4.9.0
    	 * @since 5.6.0 Added the `$previous_status` parameter.
    	 *
    	 * @param bool|null $untrash         Whether to go forward with untrashing.
    	 * @param WP_Post   $post            Post object.
    	 * @param string    $previous_status The status of the post at the point where it was trashed.
    	 */
    	$check = apply_filters( 'pre_untrash_post', null, $post, $previous_status );
    	if ( null !== $check ) {
    		return $check;
    	}

    	/**
    	 * Fires before a post is restored from the Trash.
    	 *
    	 * @since 2.9.0
    	 * @since 5.6.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( 'untrash_post', $post_id, $previous_status );

    	$new_status = ( 'attachment' === $post->post_type ) ? 'inherit' : 'draft';

    	/**
    	 * Filters the status that a post gets assigned when it is restored from the trash (untrashed).
    	 *
    	 * By default posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status`
    	 * in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()`
    	 * function is available for this.
    	 *
    	 * Prior to WordPress 5.6.0, restored posts were always assigned their original status.
    	 *
    	 * @since 5.6.0
    	 *
    	 * @param string $new_status      The new status of the post being restored.
    	 * @param int    $post_id         The ID of the post being restored.
    	 * @param string $previous_status The status of the post at the point where it was trashed.
    	 */
    	$post_status = apply_filters( 'wp_untrash_post_status', $new_status, $post_id, $previous_status );

    	delete_post_meta( $post_id, '_wp_trash_meta_status' );
    	delete_post_meta( $post_id, '_wp_trash_meta_time' );

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

    	if ( ! $post_updated ) {
    		return false;
    	}

    	wp_untrash_post_comments( $post_id );

    	/**
    	 * Fires after a post is restored from the Trash.
    	 *
    	 * @since 2.9.0
    	 * @since 5.6.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( 'untrashed_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#L4092)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post.php#L4092-L4180)

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

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

Filters whether a post untrashing should take place.

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

Fires after a post is restored from the Trash.

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

Fires before a post is restored from the Trash.

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

Filters the status that a post gets assigned when it is restored from the trash (
untrashed).

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_untrash_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_untrash_post_comments()](https://developer.wordpress.org/reference/functions/wp_untrash_post_comments/)`wp-includes/post.php` |

Restores comments for a post from the Trash.

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

Deletes a post meta field for the given post ID.

  | 
| [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_meta()](https://developer.wordpress.org/reference/functions/get_post_meta/)`wp-includes/post.php` |

Retrieves a post meta field for the given post ID.

  | 
| [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 4 more](https://developer.wordpress.org/reference/functions/wp_untrash_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_untrash_post/?output_format=md#)

| Used by | Description | 
| [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.

  |

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

| Version | Description | 
| [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | An untrashed post is now returned to `'draft'` status by default, except for attachments which are returned to their original `'inherit'` status. | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

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

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_untrash_post/?output_format=md#comment-content-6771)
 2.   [Rodrigo Vieira Eufrasio da Silva](https://profiles.wordpress.org/rodrigomct/)
    [  2 years ago  ](https://developer.wordpress.org/reference/functions/wp_untrash_post/#comment-6771)
 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_untrash_post%2F%23comment-6771)
    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_untrash_post%2F%23comment-6771)
 4.     ```php
        // Assume $post_id is the ID of the post you want to restore
        $post_id = 123;
    
        // Try to restore the post
        $restored_post = wp_untrash_post( $post_id );
    
        if ( false !== $restored_post ) {
            // The post was restored successfully, you can now do something with $restored_post
            echo 'Post restored successfully!';
        } else {
            // Restore failed or post does not exist
            echo 'Failed to restore post or post does not exist.';
        }
        ```
    
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_untrash_post%2F%3Freplytocom%3D6771%23feedback-editor-6771)

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