尝试此代码(可能有效),但我不确定原因不测试:
function amin_show_expire(){
global $wpdb;
$result = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type = \'CUSTOM\' AND post_status = \'publish\'");
if( !empty($result)) foreach ($result as $a){
$show_time = get_the_time("Y-m-d", $a->ID );
$show_time=date("Y-m-d", strtotime("+1 years", strtotime($show_time)));
if ( $show_time < date("Y-m-d")){//compare 1 year after post with current time
$my_post = array();
$my_post[\'ID\'] = $a->ID;
$my_post[\'post_status\'] = \'draft\';
wp_update_post( $my_post );
}
} // end foreach
}
add_action( \'init\', \'amin_show_expire\' );