Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#23013 closed defect (bug) (duplicate)

Gallery images don't display when original post associated with image is trashed

Reported by: nmoinvaz Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Gallery Keywords:
Focuses: Cc:


I've looked through a bunch of tickets so forgive me if this is a duplicate but I couldn't find anything like it on here.

The problem I believe is that you can assign 1 image to different galleries in different posts. If you delete the original post on which the image was first attached, then the other posts with galleries that are associated with that image will no longer display the full-sized image.

I have attached a video screencast showing the problem on one of our test sites.


Repo steps:

  1. Create post A
  2. Upload image X
  3. Create gallery in post A with image X
  4. Save post A as a draft
  5. Create post B
  6. Create gallery in post B with image X
  7. Delete post A
  8. View post B
  9. Click on image X and view full-sized image

I tracked down the issue query.php around ~ line 2700 where it does a check to see if the the attachment is public/trashed. When viewing post B it instantly gets the attachment's post_parent which is now trashed.

Change History (3)

#1 @nmoinvaz
6 years ago

I am able to get around it temporarily by changing

if ( !empty($this->posts) && ($this->is_single || $this->is_page)) { 


if ( !empty($this->posts) && (($this->is_single && !$this->is_attachment) || $this->is_page)) 
Version 0, edited 6 years ago by nmoinvaz (next)

#2 @helen
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

It's hard to tell because it only shows briefly in the screencast, but it looks like by full size image you mean the attachment page, in which case this is a duplicate of #14639

#3 @nmoinvaz
6 years ago

You are correct. This would be the same issue. Thanks for pointing me in the right direction.

Note: See TracTickets for help on using tickets.