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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.