title: WordPress Get Post Meta from Callback Function
body: <p>I'm working on my first WP plugin, and am stuck.</p>
  
  <p>I created a custom field (field 1) on the post page below the content editor. It saves correctly. :)</p>
  
  <p>I created a custom field (field 2) inside the Media Library popup when adding media. It saves correctly. :)</p>
  
  <p><strong>What I'm wanting to do, is use the value from field 1 as the default value for field 2.</strong> </p>
  
  <p>I'm suspecting that the problem lies within the <strong>attachment_fields_to_edit</strong> callback function.</p>
  
  <p>I think that $post is now referring to the actual "file attachment post" rather than the post itself, so when I'm referencing my saved values:</p>
  
  <pre><code>$post_meta = get_post_meta( $post-&gt;ID );
  </code></pre>
  
  <p>it is actually pulling all of the meta associated with that attachment, and not with the current post. Is it possible to pull the meta from the actual post? </p>
  
  <p>This code is from the Codex:</p>
  
  <pre><code>function my_add_attachment_location_field( $form_fields, $post ) {
      $field_value = get_post_meta( $post-&gt;ID, 'location', true );
      $form_fields['location'] = array(
          'value' =&gt; $field_value ? $field_value : '',
          'label' =&gt; __( 'Location' ),
          'helps' =&gt; __( 'Set a location for this attachment' )
      );
      return $form_fields;
  }
  add_filter( 'attachment_fields_to_edit', 'my_add_attachment_location_field', 10, 2 );
  
  function my_save_attachment_location( $attachment_id ) {
      if ( isset( $_REQUEST['attachments'][$attachment_id]['location'] ) ) {
          $location = $_REQUEST['attachments'][$attachment_id]['location'];
          update_post_meta( $attachment_id, 'location', $location );
      }
  }
  add_action( 'edit_attachment', 'my_save_attachment_location' );
  </code></pre>
  
  <p>How would I get_post_meta for the current post that we are inserting the attachment into? This would need to happen in the my_add_attachment_location_field callback function in the codex code above.</p>
  
  <p>Thanks!</p>