Automatisch de (custom) posts op concept zetten indien een ACF datum veld verstreken is. Deze functie is voornamelijk handig als expired posts.
//Draai alleen als die nog niet op de cron lijst staat
if (!wp_next_scheduled('expire_posts')){
wp_schedule_event(time(), '5min', 'expire_posts',10);
}
add_action('expire_posts', 'expire_posts_function');
function expire_posts_function() {
$today = date('Ymd');
$args = array(
'post_type' => array('vacatures'), // post type
'posts_per_page' => -1
);
$posts = get_posts($args);
foreach($posts as $p){
$expiredate = get_field('verloop_datum', $p->ID, false, false); // ACF veld
if ($expiredate) {
if($expiredate < $today){
$postdata = array(
'ID' => $p->ID,
'post_status' => 'draft'
);
wp_update_post($postdata);
}
}
}
}
#acf #cron #expired #verlopen