The issue likely arises because, when the post is created programmatically, the event_date field is not fully recognized by WordPress until the post is saved manually. This can happen if the date value isn’t stored correctly in the database, or if it’s missing necessary metadata or cache refresh. Here are a couple of solutions to ensure the date is stored and recognized correctly for sorting:
$event_date = '2024-10-31'; // Example date format 'Y-m-d' update_field('event_date', $event_date, $post_id);