wp_untrash_post( int $post_id )

Restore a post or page from the Trash.


Description Description


Parameters Parameters

$post_id

(int) (Optional) Post ID. Default is ID of the global $post.


Top ↑

Return Return

(WP_Post|false) WP_Post object. False on failure.


Top ↑

Source Source

File: wp-includes/post.php

function wp_untrash_post( $post_id = 0 ) {
	if ( !$post = get_post($post_id, ARRAY_A) )
		return $post;

	if ( $post['post_status'] != 'trash' )
		return false;

	/**
	 * Fires before a post is restored from the trash.
	 *
	 * @since 2.9.0
	 *
	 * @param int $post_id Post ID.
	 */
	do_action( 'untrash_post', $post_id );

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

	$post['post_status'] = $post_status;

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

	wp_insert_post( wp_slash( $post ) );

	wp_untrash_post_comments($post_id);

	/**
	 * Fires after a post is restored from the trash.
	 *
	 * @since 2.9.0
	 *
	 * @param int $post_id Post ID.
	 */
	do_action( 'untrashed_post', $post_id );

	return $post;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.9.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.