I created a custom taxonomy to organize Media Library.
The code below works for built-in feature of WP such as featured image or Media Library uploader, but does not work with Metabox field.
I'd like to set a default term to files uploaded from cpt post.
function set_media_category($post_ID){
if(!empty($_POST['post_id']) && get_post_type($_POST['post_id'])=='cpt'){ wp_set_object_terms($post_ID,102,'media_category'); }
else{ wp_set_object_terms($post_ID,103,'media_category'); }
}
add_action('add_attachment','set_media_category',30,1);
add_action('edit_attachment', 'set_media_category',30,1);