WordPress.org

Ready to get started?Download WordPress

Forums

How do you access the media gallery in plugin code... (2 posts)

  1. Zooney
    Member
    Posted 4 years ago #

    Hello,

    I'm trying to write a plugin that will be able to use an image from the media gallery or information from the whole "Add media" as postmeta.

    Can anyone out there point me in the direction of whatever part of the API, etc. allows me to access the "Add Media" window to allow people to upload something to the media gallery and then take the location of that image in the gallery and store it as post meta?

    Thanks in advance for any pointers. I'm trying to reverse engineer other gallery/slideshow plugins that don't do exactly what I need, but it's slow going.

    ...and I just can't seem to find anything in the WordPress docs on how to manipulate the media gallery for use in plugin development.

  2. Zooney
    Member
    Posted 4 years ago #

    Doink, I've answered my own question by studying xen_carousel.

    The linchpin in doing something like this is to realize that everything in the media gallery is simply stored in $wbdb->posts with the post_type column set as "attachment". I'd never realized that's where everything in the media gallery is stored!

    So, to access items in the media gallery in plugin code you simply need to do a query for attachments in the posts table.

    To make a clever interface to search and select images and store them as post meta, I've found I just need to do some AJAX magic and perform such a query.

    Woooo!

Topic Closed

This topic has been closed to new replies.

About this Topic