I actually just got this issue worked out. Turns out I didn’t do my due diligence in tracing the problem, and the actual root cause was an error earlier on in the script when I was uploading image via the WordPress API. In case anyone else has this issue later on, the problem was that the authentication information wasn’t being passed along correctly. I needed to install the Application Passwords plugin and make an edit to my .htaccess (detailed here) to resolve that issue, which in turn allowed the code to finish executing.