docs icon indicating copy to clipboard operation
docs copied to clipboard

media API Accessibility Dependent on Parent Post Status for Initially Uploaded Media

Open naokiuma opened this issue 6 months ago • 1 comments

Hi. I kindly ask you to consider this.

■Problem Description

When media (e.g., an image) is first uploaded directly within a post's editing screen, that post becomes the media item's parent. If this parent post is then set to a private status (or deleted), the media item itself also becomes inaccessible via the media REST API endpoint.

https://example.com/wp-json/wp/v2/media

This behavior was observed and verified through testing.

This creates an unexpected dependency where media accessibility through the API is tied to the privacy status of its initial parent post, even if that media is later used in other public posts. This can lead to broken media links or inaccessible assets when consuming media via the API.

■Expected Behavior

Media uploaded to WordPress should remain accessible via the /media REST API endpoint regardless of the privacy status of the post it was initially uploaded through. Its accessibility should ideally be determined by its own status or its usage in publicly accessible content, rather than being strictly tied to a single "parent" post's private status if that parent is merely the point of initial upload.

■Proposed Solution / Workaround

It is suggested that this behavior be documented on pages like https://developer.wordpress.org/rest-api/reference/media/ as a note of caution regarding the accessibility of media items, especially those initially uploaded within a post.

naokiuma avatar Jul 09 '25 13:07 naokiuma

Break the parent post link (manual or automated) If you don’t need the media tied to the original post: After uploading, edit the media item in the Media Library. In the database, the media’s post_parent field (in wp_posts) can be set to 0.

This will make it an “orphan” media item, not tied to any post, so it won’t be hidden when the original post becomes private. UPDATE wp_posts SET post_parent = 0 WHERE ID = <media_id>;

wp_update_post([ 'ID' => $media_id, 'post_parent' => 0 ]);

vinay070403 avatar Aug 13 '25 06:08 vinay070403