Howdy! I am looking for a way to list all of the image files in a posts’ media library.
What I mean by this is if a file has been uploaded while creating or editing a post, is the file associated with the post in some way, and can I create a list from this data.
I think that the next_image_link() / previous_image_link(); template tag is as close as I have found.
I think that this should be close:
$query = 'SELECT * FROM `wp_posts`
WHERE `post_parent` = ''.$_GET['post_id'].''
AND `post_mime_type` = 'image/jpeg'
ORDER BY `menu_order` ASC';
thanks.
In wordpress terminology, every image you uploaded to particular post is called attachment.
To list all attachment, you can use get_children() function:
The algorithm is something like that.
If you are looking for a plugin to manage image gallery, you can use
attachments
plugin,http://wordpress.org/plugins/attachments/
It keeps the gallery separate and does not put the image gallery shortcodes in post content, thus providing you with full hold over image display in your post/page/custom post. You can also change the order of your images by just drag-n-drop
here is a sample code of how to retrieve your gallery images,