在你的第一句话中,我假设你的意思是,你有一个自定义的帖子类型(不是时间)。
因此,post有一个连接的包,该包有一个活动天数设置。阅读您的示例代码,我认为您从错误的角度来理解这一点。
我会这样做:
// I don\'t know how you want to call this function, i would use a daily cron-job
function remove_expired_posts() {
$current_date = new DateTime();
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'YOUR_CUSTOM_POST_TYPE_NAME_HERE\',
\'post_status\' => \'publish\',
);
$posts = get_posts( $args );
if($posts) {
foreach($posts as $post) {
$post_id = $post->ID;
$post_date = DateTime::createFromFormat(\'Y-m-d H:i:s\', $post->post_date\');
$package_id = get_post_meta( $post_id, \'package_select\', true );
$transaction_price_pkg = $monetization->templ_get_price_info( $package_id, \'\' ); // make sure you include the $monetization object
$alive_days = (int)$transaction_price_pkg[0][\'alive_days\'];
$expire_date = $post_date->modify(\'+ \'.$alive_days.\' days\');
if($current_date > $expire_date) {
wp_delete_post( $post_id, true ); // true means bypass bin.
}
}
}
}
NOTE:我尚未测试此代码,但它应该可以工作。至少它应该给你一个如何继续的想法。
尊敬的Bjorn