do_action( ‘wp_trash_post’, int $post_id, string $previous_status )

Fires before a post is sent to the Trash.

Parameters

$post_idint
Post ID.
$previous_statusstring
The status of the post about to be trashed.

Source

do_action( 'wp_trash_post', $post_id, $previous_status );

Changelog

VersionDescription
6.3.0Added the $previous_status parameter.
3.3.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    To get the id of all posts that have been trashed when selecting multiples, you must use the

    $_GET['post']

    Like that example below:

    function wpdocs_trash_multiple_posts( $post_id = '' ) {
        // Verify if is trashing multiple posts
        if ( isset( $_GET['post'] ) && is_array( $_GET['post'] ) ) {
            foreach ( $_GET['post'] as $post_id ) {
                wpdocs_your_function( $post_id );
            }
        } else {
            wpdocs_your_function( $post_id );
        }
    }
    add_action( 'wp_trash_post', 'wpdocs_trash_multiple_posts' );

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