• Is there a way to query for images in the media libary? I want to have a bar on my page that show the most recent 5 uploaded photos, but cannot figure out how to make the images get to the page through php. Any help?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You could grab that last 5 attached images using query_posts or get_posts.

    Thread Starter hatefulcrawdad

    (@hatefulcrawdad)

    so by “attached” you mean they would have to be part of a blog post? They can’t just be images that I upload straight into the Media Library?

    so by “attached” you mean they would have to be part of a blog post?

    Yes. All of the methods that I know of focus on listing attachments – such as wp_get_attachment_image. I can’t even think of a native function that lists images as non-attachments.

    Have you tried looking for some sort of gallery plugin? Perhaps one that has it’s own upload?

    Thread Starter hatefulcrawdad

    (@hatefulcrawdad)

    Have you tried looking for some sort of gallery plugin? Perhaps one that has it’s own upload?

    I have looked around, but most of them seem to be more advanced than what I’m looking for. I’m simply having a page where it just lists clickable thumbnails of all the photos in the Media library, well thats what I want to have. I know I could just make a post and past the url’s in it, but I wanted something easier. I figured WP would have something native for posting things from the media library, strange that it doesn’t.

    For now I suppose I can just upload the images to blog posts as the method of uploading so that it will work. But I also don’t want to have to show a bunch of images with a blog if I want to upload pics from a trip or something.

    I’m definitely looking for the same type of function.

    I think it’s really sort of short-sighted to only allow the querying of images that are attached to a post or page. I have a plugin installed that allows me to tag media, for example, so I’d like to be able to query on that media’s tags (media seems to function like a post anyway, right)?

    Also, I have a section where I allow the user to specify a media attachment’s ID. I’d then like to take this ID and query the media object with it…and I’d like to do it via WordPress’ built in functionality…but it doesn’t seem like that exists! I guess I have to resort to writing some SQL statement :-(.

    I can query the media object with the get_attachment_metadata() function…but for some reason that function fails to return the caption, description and other data that can be inserted besides the actual object! What gives?

    Okay, I’ve figured out a way to grab your media items using the ID of that media object:

    $post = get_post($media_item_id);
    
    if($post && $post->post_type == 'attachment')
      $attachment = array($post->ID => $post);
    print_r($attachment);

    Now you can use that data to with whatever you wish. It should contain all of the fields relating to the media object.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display images in Media Library’ is closed to new replies.