title: Get attachment urls for a post - WordPress
body: <p>I am trying to create a list of PDFs (newsletters created each month). I have created a custom post type named 'newsletters' and restricted it to only supporting a 'title'.</p>
  
  <p>I have then used the advanced custom fields plugin to add a file upload button to this post type. Therefore each post has a title and a button to upload the pdf.</p>
  
  <p>I have then written the below function to output the list of attachments.</p>
  
  <pre><code>function list_newsletters(){
  
      $args = array( 'post_type' =&gt; 'newsletters' );
      $loop = new WP_Query( $args );
      while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();
          $permalink = get_permalink();
          $title = get_the_title();
          $id = get_the_ID();
          $attachment = wp_get_attachment_url($id);
          echo '&lt;li&gt;&lt;a href="'.$attachment.'"&gt;'.$title.'&lt;/li&gt;';
      endwhile;
  
  }
  </code></pre>
  
  <p>However the wp_get_attachment_url($id) doesn't seem to work. I think this is because I am supposed to be supplying the attachment ID rather than the post ID. I have looked around online and cannot find a clear way of finding the attachment ID for a specific post.</p>
  
  <p>Just to clarify each post will only contain one attached file.</p>
  
  <p>Thank you in advance</p>