Halloween Sale 15% off Ends in See the plans
PHP

Register an "Archived" Post Status

Adds an "Archived" status for posts that should leave the site without being deleted, with its own filter link in the Posts list and a status choice in the editor.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'init', function () {
    register_post_status( 'wpide_archived', array(
        'label'                     => 'Archived',
        'public'                    => false,
        'protected'                 => true,
        'exclude_from_search'       => true,
        'show_in_admin_all_list'    => false,
        'show_in_admin_status_list' => true,
        /* translators: %s: number of posts */
        'label_count'               => _n_noop( 'Archived <span class="count">(%s)</span>', 'Archived <span class="count">(%s)</span>' ),
    ) );
} );

add_action( 'admin_footer-edit.php', function () {
    global $post_type;

    if ( 'post' !== $post_type ) {
        return;
    }
    ?>
<script>
jQuery(function ($) {
    $('select[name="_status"]').append('<option value="wpide_archived">Archived</option>');
});
</script>
    <?php
} );

add_filter( 'display_post_states', function ( $states, $post ) {
    if ( 'wpide_archived' === $post->post_status && ( ! isset( $_GET['post_status'] ) || 'wpide_archived' !== $_GET['post_status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
        $states['wpide_archived'] = 'Archived';
    }

    return $states;
}, 10, 2 );

Notes

Archived posts are not public. Set them via Quick Edit or the status dropdown in the block editor's summary panel.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.