# Bulk Action to Move Posts Back to Draft

> Adds "Move to draft" to the Bulk actions menu for posts and pages, to unpublish several items at once.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin, bulk-actions, drafts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/bulk-move-to-draft/

## Code

```php
// Post types that get the bulk action.
$wpide_to_draft_types = array( 'post', 'page' );

foreach ( $wpide_to_draft_types as $wpide_draft_type ) {
    add_filter( "bulk_actions-edit-{$wpide_draft_type}", function ( $actions ) {
        $actions['wpide_to_draft'] = 'Move to draft';

        return $actions;
    } );

    // WordPress checks the bulk action nonce before this filter runs.
    add_filter( "handle_bulk_actions-edit-{$wpide_draft_type}", function ( $redirect, $action, $post_ids ) {
        if ( 'wpide_to_draft' !== $action ) {
            return $redirect;
        }

        $done = 0;

        foreach ( (array) $post_ids as $post_id ) {
            if ( current_user_can( 'edit_post', $post_id ) && 'draft' !== get_post_status( $post_id ) ) {
                $result = wp_update_post( array( 'ID' => (int) $post_id, 'post_status' => 'draft' ), true );
                $done  += is_wp_error( $result ) ? 0 : 1;
            }
        }

        return add_query_arg( 'wpide_drafted', $done, $redirect );
    }, 10, 3 );
}

add_action( 'admin_notices', function () {
    if ( isset( $_GET['wpide_drafted'] ) ) {
        $count = absint( $_GET['wpide_drafted'] );
        printf( '<div class="notice notice-success is-dismissible"><p>%s</p></div>', esc_html( sprintf( _n( '%d item moved to draft.', '%d items moved to draft.', $count ), $count ) ) );
    }
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Bulk Action to Move Posts Back to Draft" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
