Custom Post Status 404 URL

时间:2022-01-21 作者:Huw Rowlands

我有一个函数,在一定时间后过期。它还设置自定义post状态\'expired\'. 我希望它能像\'draft\' 发布URL不再可供公众访问。目前,一旦岗位设置为\'expired\', 整个permalink仍然可见。这是我的代码:

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
wp_update_post($postdata);

2 个回复
SO网友:tiago calado

此函数将帖子更改为草稿,您只需调用它并将帖子id传递给希望该函数工作的位置

function postToDraft($post_id){
    $post = array( \'ID\' => $post_id, \'post_status\' => \'draft\' );
    wp_update_post($post);
}

SO网友:Huw Rowlands

这一行代码:

\'public\' => true,

更改为

\'public\' => false,