Title: Attachment Help
Last modified: August 19, 2016

---

# Attachment Help

 *  Resolved [WalletStation](https://wordpress.org/support/users/dkn/)
 * (@dkn)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/attachment-help/)
 * Hello,
 * I’m currently using the following to display attachments:
 *     ```
       <?php
       global $wpdb;
       $attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");
       ?>
       <?php the_attachment_link($attachment_id); ?>
       ```
   
 * Is there an if statement I could use where if there is an attachment display 
   the above code I posted, and if there isn’t an attachment display nothing?

The topic ‘Attachment Help’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [WalletStation](https://wordpress.org/support/users/dkn/)
 * Last activity: [17 years, 6 months ago](https://wordpress.org/support/topic/attachment-help/)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
