I have a function that expires posts after a certain amount of time. It also sets a custom post status of 'expired'. I would like it to function like a 'draft' post in that the URL is no longer accessible to the public. At the moment, once the post is set to 'expired', the full permalink is still visible. Here is my code:

function hrl_custom_status_creation(){
    register_post_status( 'expired', array(
        'label'                     => _x( 'Expired', 'post_type_listings' ),
        'label_count'               => _n_noop( 'Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'protected' => true,
        '_builtin'  => true
add_action( 'init', 'hrl_custom_status_creation' );

// change post status to 'expired'
                $postdata = array(
                    'ID'          => $post_id,
                    'post_status' => 'expired',

// Update post data

2 Answers 2


this function changes the post to draft, you only have to call it and pass the post id where you want the function to work

function postToDraft($post_id){
    $post = array( 'ID' => $post_id, 'post_status' => 'draft' );
  • I would like my custom post status to mimic the draft status, not actually change it to draft. Is this possible? Jan 22 at 20:39

This line of code:

'public' => true,

change to

'public' => false,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.