你的问题不是很清楚。
你的意思是:
1天后koncerter_start_date
具有自定义帖子类型的所有帖子koncert
必须获取状态draft
?
<小时>
EDIT
代码:
add_action( \'wp_loaded\', \'concert_daily_tasks\' );
function concert_daily_tasks() {
$current_url = "https://" . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'];
if ( $current_url == \'https://example.com/concert-daily-tasks\' ) { // <-- set the correct URL!
check_concert_status();
}
}
function check_concert_status() {
$today = new DateTime();
$concert_start_date_str = \'2018-10-10\'; // I\'m not sure where/how you get this data.
$concert_start_date = DateTime::createFromFormat(\'Y-m-d\', $concert_start_date_str); // make sure the format (\'Y-m-d\') matches $concert_start_date_str
if($concert_start_date) {
if($concert_start_date->modify(\'+1 day\') <= $today) { // if concert start day was yesterday (or older) continue
$args = array(
\'posts_per_page\' => -1, // get all posts
\'post_type\' => \'koncert\',
\'post_status\' => \'publish\',
);
$posts = get_posts($args);
if($posts) {
foreach($posts as $post) {
wp_update_post(array(
\'ID\' => $post->ID,
\'post_status\' => \'draft\',
));
}
}
}
}
}
Important:完成$concert\\u start\\u date\\u str集合,请参阅脚本可以将其放入函数中。当您转到https://example.com/concert-daily-tasks
代码将运行。您可能可以在主机面板中设置acron作业计划