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?

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

Leave a Reply

Your email address will not be published. Required fields are marked *