Then I think it’s the missing post ID.
The query filter/function is located in my child theme’s functions.php.
The code snippet is inserted directly into the post via shortcode by a plugin that enables php code through a shortcode. It’s not in a template file.