Can’t call WPDB inside RSS template

After discussing we’ve discovered the problem isn’t directly with calling $wpdb->get_row but a mismatch between the data it returns and the processing in the foreach loop.

For a single row of data, replacing…

foreach($beforeAfter as $imageSet) { ?>
    <item>
        <title><?php echo get_the_title($imageSet->ID); ?></title>
    </item>
<?php }

… with …

<item>
    <title><?php echo get_the_title($imageSet->ID); ?></title>
</item>

… stops the feed erroring.

Or for multiple rows you could adjust your query.