The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. hilj
    Posted 5 years ago #


    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
    Posted 5 years ago #

    I think you can use the 'post_mime_type' field to select a certain type of attachment:

    $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