WordPress.org

Support

Support » How-To and Troubleshooting » Is there a way to get all the pdf files attached to a post?

Is there a way to get all the pdf files attached to a post?

  • Hello,

    It’s easy to pull all the images attached to a post. But is there a way to pull only attached pdf’s?

    I find this useful when building a press release page, usually on press page there a hi-res images and press release as pdf.

    Thank you 🙂

Viewing 1 replies (of 1 total)
  • I think you can use the ‘post_mime_type’ field to select a certain type of attachment:

    <?php
    $args = array( 'post_mime_type' => 'application/pdf', 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ( $attachments as $attachment ) {
    		echo apply_filters( 'the_title' , $attachment->post_title );
    		the_attachment_link( $attachment->ID , false );
    	}
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Is there a way to get all the pdf files attached to a post?’ is closed to new replies.