Error accessing media through REST API when associated post is deleted.

[ad_1]

I discovered a weird bug that happens when I upload an image directly inside a post (for instance, as a featured image). When that post gets deleted, the image suddenly becomes inaccessible through the REST API and only returns a 401 error. This doesn’t happen if I upload an image through the main Media page.

Anyone know a way to fix this? I’m making this website for a client and I’m guessing they’ll find it very inconvenient to have to upload images through the Media page every time to avoid potential errors.

[ad_2]
1 Comment
  1. Well, it’s possible that the issue you’re experiencing is related to the way WordPress handles attachments and media. When you upload an image directly inside a post, it is automatically attached to that post as a “post attachment.” If you delete the post, the attachment is also deleted, which can make the image inaccessible through the REST API.

    I’d suggest you try create a new post and upload the image as a post attachment, copy the URL of the image from the “Media Library” page and then use the URL to access the image through the REST API.

    Alternatively, you can try using a plugin like WP-REST-API V2 Menus to manage attachments and media through the REST API.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer