codex.wordpress.org – 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
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.
The topic ‘codex.wordpress.org – Show attachments for the current post – BUG?’ is closed to new replies.