title: Wordpress get URL of a post from its attachment
body: <p>I am adding an image from media in every single post that are created.
  To get the attached image and url of that post, I am implementing this code:</p>
  
  <pre><code>$args = array(
  'post_type' =&gt; 'attachment',
  'post_mime_type' =&gt; 'image',
  'numberposts' =&gt; 5,
  'post_status' =&gt; null,
  'post_parent' =&gt; 'any', // any parent
  );
  $attachments = get_posts($args);
  if ( $attachments ) {
  foreach ( $attachments as $attachment ) {
      setup_postdata($attachment);
      $v =$attachment-&gt;ID;
      $imageurl = wp_get_attachment_url($v);
      $postlink = get_permalink($v);
  }
  </code></pre>
  
  <p>The above code works fine for retrieving image url. My question is how do I pass post ID in get_permalink() to make sure that I get link of that post. I know that passing $v in get_permalink() is wrong.</p>