How to get all post attachments of a certain file type

<?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>';
          }
        }
    ?>

Revisions

There are no revisions for this post.

Tags:

No comments yet.

Leave a Reply