我已经做了更多的研究,并阅读了下面的文章,这篇文章正是我想要它做的。根据作者的说法,代码是可行的,但当我尝试根据自己的情况调整代码时,它不会更新帖子状态。有人能告诉我我做错了什么吗?
原始代码:
$ap = get_post_meta($post->ID,\'sub_seminars_0_start_date\',true);
$startdate = date("Ymd", strtotime($ap));
$todaydate = date("Ymd");
if(strtotime($todaydate) > strtotime($startdate) && !empty($ap)){
$del_data = array(
\'Ref\' => \'sub_seminars_0_ref\',
\'Start date\' => \'sub_seminars_0_start_date\',
\'End Date\' => \'sub_seminars_0_end_date\',
\'Venue\' => \'sub_seminars_0_venue\',
\'Fees\' => \'sub_seminars_0_fees\',
\'CPE Credits\' => \'sub_seminars_0_cpe_credits\'
);
delete_row(\'sub_seminars\', 1);
这是我函数中的代码。php文件:
function expire_posts () {
$post_id = get_the_ID();
$getdate = get_post_meta($post_id, \'Expiry Date\', true);
$expirydate = date ( \'d F Y\', strtotime ($getdate));
$today = date( \'d F Y\' );
if ( strtotime($expirydate) < strtotime($today) ) {
$postdata = ( array (
\'ID\' => $post_id,
\'post_status\' => \'expired\',
\'post_modified\' => $today,
)
);
wp_update_post ($postdata);
}
}