WordPress.org

Ready to get started?Download WordPress

Forums

Is there a way to get all the pdf files attached to a post? (2 posts)

  1. hilj
    Member
    Posted 3 years ago #

    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 :)

  2. vtxyzzy
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic