I'm calling media-upload.php via a custom icon click inside the content editor and I would like to add a custom meta value for all images that are uploaded when the media-upload.php is called from my custom function.

For example, for each of the images that are uploaded, I want to insert a value into wp_postmeta of _customAttachment = 1 like so:

update_post_meta($post['ID'], '_customAttachment', true);

I know how I can pass the current post-id to the media-upload.php (via querystring parameters), but I have no idea how to attach my update_post_meta filter to the save/upload trigger in media-upload.php

Is there a filter for this?

  • would you mind please sharing your full solution here? Inane been trying to find a slick way to create a custom attach file/image feature to the post edit screen which uses the default media library while forcing any new upload or attachment done from that specific custom post type screen to have custom metadata appended to the files post meta table... Please do share! Nov 29, 2010 at 18:45

1 Answer 1


Yes, you can add fields, an example

function rt_image_attachment_fields_to_save($post, $attachment) {
    // $attachment part of the form $_POST ($_POST[attachments][postID])
        // $post['post_type'] == 'attachment'
    if( isset($attachment['rt-image-link']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post['ID'], '_rt-image-link', $attachment['rt-image-link']);
    return $post;
// now attach our function to the hook.
add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2);

see more on this post

  • I'm almost there, however, I want to add the custom meta "_imageTop" to every attachment thats uploaded. Why do you check for isset()?
    – Scott B
    Nov 19, 2010 at 18:49
  • when empty this field, then you have an php warning, thats all
    – bueltge
    Nov 19, 2010 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.