Thanks for the quick reply!
It didn’t work because I think line 13 needs to be changed from:
$post_ids[] = $post->ID; // Build array of post IDs
to:
$post_ids[] = $the_query->post->ID; // Build array of post IDs
After that, it worked for me. New WordPress versions are probably the reason, idk.
Thanks again for getting me on track!