Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#23434 closed defect (bug) (duplicate)

post_parent update

Reported by: reliability's profile reliability Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

Description

I've tried to find similar tickets but was unsuccessful. So, I apologize if this is a duplicate.

Consider the following steps:

  1. Upload an image A to the media library.
  2. Create a new post P1 and insert the image A.
  3. Create another post P2 and insert the image A.

The post_parent property of A will be set to the id of P1. But when adding the image to the post P2, no new post-entry for A with the post_parent-id of P2 is added to the wp_posts-table.

The effect of this is, while the image is properly displayed when the content of post P2 is rendered, code that retrieves images that are attached to P2 fails. For instance:

/* ... */
$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image' ) );
/* ... */

Change History (3)

#1 @markoheijnen
12 years ago

  • Keywords close added

This is default behavior. The image can only be attached to one post. #16349 is somehow duplicated to this one.
Seems it's not really something we should taken care of in core.

#2 @helen
12 years ago

  • Component changed from General to Media
  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

markoheijnen is correct - an attachment (which is a post type) can only be attached to one post, as it uses post_parent for that relationship, which can only hold one post. I think this is more a duplicate of #10657.

#3 @reliability
12 years ago

Thanks for the quick reply.

However, that means that, for instance, in the twentyeleven theme, the gallery-template (content-gallery.php) that previews the first attached image of a gallery inside a gallery-post is broken, since it uses exactly the method I described in the ticket to retrieve the images a particular blog-post contains. Or, in other words, this code relies on that at least one image of the gallery is attached the first time in the current blog post.

Note: See TracTickets for help on using tickets.