Title: Get latest image with php?
Last modified: August 20, 2016

---

# Get latest image with php?

 *  [deepseaengine](https://wordpress.org/support/users/deepseaengine/)
 * (@deepseaengine)
 * [14 years ago](https://wordpress.org/support/topic/get-latest-image-with-php/)
 * I’m desperately trying to create a really simple table-based gallery of the latest
   3 uploaded images. My table is styled and all I need is to be able to call the
   image and place a thumbnail in each of the three table cells.
 * I’ve looked at gallery plugins (none seem to style how I want) and even the Get
   the Image php plugin, which I can’t figure out. Can anyone help?

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/get-latest-image-with-php/#post-2698591)
 * I think this query will do what you want:
 *     ```
       $sql = "
       SELECT p.ID, p.guid, pm.meta_value FROM $wpdb->posts p
       JOIN $wpdb->postmeta pm ON (p.ID = pm.post_id AND pm.meta_key = '_wp_attachment_metadata')
       WHERE p.post_type = 'attachment'
       AND p.post_mime_type LIKE '%image%'
       ORDER BY p.post_date DESC
       LIMIT 0,3
       ";
       ```
   
 * I tested this using this code:
 *     ```
       $img_ids = $wpdb->get_results($sql);
       foreach ($img_ids as $img) {
          $img_meta = unserialize($img->meta_value);
          $hw = $img->hwstring_small;
          echo "<p>";
          echo '<img ' . $hw . "src='$img->guid' alt='' />";
          echo '</p>';
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Get latest image with php?’ is closed to new replies.

## Tags

 * [image](https://wordpress.org/support/topic-tag/image/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/get-latest-image-with-php/#post-2698591)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
