Title: Attachments conditional php
Last modified: August 20, 2016

---

# Attachments conditional php

 *  [Marco Milesi](https://wordpress.org/support/users/milmor/)
 * (@milmor)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/attachments-conditional-php/)
 * Hello everyone!
 * I’ve this code in all my pages:
 *     ```
       <ul>
           <?php
               $args = array(
                 'post_type' => 'attachment',
                 'post_mime_type' => 'application/pdf,application/msword',
                 'numberposts' => -1,
                 'post_status' => null,
                 'post_parent' => $post->ID,
                 'orderby' => 'menu_order',
                 'order' => 'desc'
                 );
               $attachments = get_posts($args);
               if ($attachments) {
                 foreach ($attachments as $attachment) {
                   echo '<li><a href="'.wp_get_attachment_url($attachment->ID).'">';
                   echo $attachment->post_title;
                   echo '</a></li>';
                 }
               }
           ?>
           </ul>
       ```
   
 * It works perfectly but i didn’t succeeded in hiding the output list in pages 
   which don’t have attachments.
    So, is there a function like **If post have attachments**?
 * Thanks to everyone in advance

The topic ‘Attachments conditional php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Marco Milesi](https://wordpress.org/support/users/milmor/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/attachments-conditional-php/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
