wp_trash_post
Move a post or page to the Trash.
Description
(false|array|WP_Post|null) wp_trash_post( (int) $post_id = 0 );
If trash is disabled, the post or page is permanently deleted.
Returns (false|array|WP_Post|null)
Post data array, otherwise false.
Parameters (1)
- 0. $post_id — Optional. (int)
- Post ID. Default is ID of the global
$post
if EMPTY_TRASH_DAYS equals true.
Usage
if ( !function_exists( 'wp_trash_post' ) ) { require_once ABSPATH . WPINC . '/post.php'; } // Optional. Post ID. Default is ID of the global $post // if EMPTY_TRASH_DAYS equals true. $post_id = -1; // NOTICE! Understand what this does before running. $result = wp_trash_post($post_id);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/post.php
- function wp_trash_post( $post_id = 0 ) {
- if ( !EMPTY_TRASH_DAYS )
- return wp_delete_post($post_id, true);
- return $post;
- if ( $post['post_status'] == 'trash' )
- return false;
- /**
- * Fires before a post is sent to the trash.
- *
- * @since 3.3.0
- *
- * @param int $post_id Post ID.
- */
- do_action( 'wp_trash_post', $post_id );
- add_post_meta($post_id, '_wp_trash_meta_status', $post['post_status']);
- add_post_meta($post_id, '_wp_trash_meta_time', time());
- $post['post_status'] = 'trash';
- wp_insert_post( wp_slash( $post ) );
- wp_trash_post_comments($post_id);
- /**
- * Fires after a post is sent to the trash.
- *
- * @since 2.9.0
- *
- * @param int $post_id Post ID.
- */
- do_action( 'trashed_post', $post_id );
- return $post;
- }