Title: codex.wordpress.org &#8211; Show attachments for the current post &#8211; BUG?
Last modified: August 20, 2016

---

# codex.wordpress.org – Show attachments for the current post – BUG?

 *  [phillipcc](https://wordpress.org/support/users/phillipcc/)
 * (@phillipcc)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/codexwordpresscom-show-attachments-for-the-current-post-bug/)
 * I’m trying to find a reliable way to get all attachments from a given post id
   and didn’t find a reliable answer, even following the instructions from the wordpress
   manual below:
 * Section – Show attachments for the current post [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
 * All the solutions I found on the internet as well as codex.wordpress use the 
   same technique: get all posts type attachment where post parent equals a given
   post id. Sounds good!
 * Imagine the following scenario: – create a post, id 5 for example for reference–
   now lets attach an image into the post 5 and save. The new media file creates
   a post id 6 type attachment with parent_id 5. So far so good.
 * Problem 1: if I remove the image from the post id 5 and save, in the database
   the post type attachment (the image id 6) parent_id field still 5. This will 
   lead to an error.
 * Problem 2: if we create a second post, for example id 7, and then insert the 
   same image id 6 and save. The post type attachment id 6 always keeps the parent_id
   of the first post, id 5.
 * I can’t trust the query where I search for post type attachment where parent_id
   equals post id.
 * Am I wrong?
 * Waiting for comments.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/codexwordpresscom-show-attachments-for-the-current-post-bug/#post-2829940)
 * wordpress.com ?
 *  Thread Starter [phillipcc](https://wordpress.org/support/users/phillipcc/)
 * (@phillipcc)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/codexwordpresscom-show-attachments-for-the-current-post-bug/#post-2829944)
 * Sorry wordpress.org
 * Any thoughts on the subjet?
 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/codexwordpresscom-show-attachments-for-the-current-post-bug/#post-2830156)
 * Are these db entries [serialized](http://codex.wordpress.org/Function_Reference/maybe_serialize)?
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/codexwordpresscom-show-attachments-for-the-current-post-bug/#post-2830159)
 * Interesting…
 * How are you removing the image from your (hypothetical) post ID = 5 ? What are
   the steps?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘codex.wordpress.org – Show attachments for the current post – BUG?’ is
closed to new replies.

## Tags

 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/codexwordpresscom-show-attachments-for-the-current-post-bug/#post-2830159)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
