ACF saves the value as Ymd
format in database regardless of display and return format. All you need is a meta query to fetch the correct posts.
function expire_posts_function() {
//Get Expired Posts only
$expired_posts = get_posts(arrasy(
'post_type' => 'event',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'ev_date',
'value' => date('Ymd'),
'compare' => '<',
),
),
));
//Loop through the posts and set status
if ( $expired_posts ) {
foreach( $expired_posts as $expired_post ) {
wp_insert_post(array(
'ID' => $expired_post->ID,
'post_status' => 'draft',
));
}
}
}