• I’m building a gallery plugin. I have an array of image IDs, and I want the most efficient way to get the full url of those images, but in multiple sizes. For example, I need the “Full” url for the expanded view, and the “Thumbnail” url for the slider control.

    I’ve noticed that wp_get_attachment_image will return the “file” but that’s relative to the directory it’s uploaded to (which might be set to month/year).

    What’s the best way to return the entire url?

    • This topic was modified 2 years, 1 month ago by oguruma.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    wp_upload_dir() will return relevant information about the uploads folder. The “url” element will include the year/month folders related to the passed time parameter. The “baseurl” element will be just the uploads folder’s URL, no sub-folders. You can then concatenate the file’s relative path to it.

    If you need a variety of data for a particular image, you could get most of its metadata in one go with something like get_post_meta( $attachment_id, '_wp_attachment_metadata', true ). This will return an array of data related to all the available sizes, and then some. var_dump() the returned array to see what sort of data is available.

    Thread Starter oguruma

    (@oguruma)

    It’s interesting that it doesn’t return the entire relative directory in any url except for the [‘file’]….

    Meaning the [‘sizes’] don’t return the path with respect to the year/month…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get multiple sizes of same image?’ is closed to new replies.