试试这个方法,应该很管用
function cpt_from_attachment($attachment_ID)
{
global $current_user;
get_currentuserinfo();
$attachment_post = get_post( $attachment_ID );
$type = get_post_mime_type($attachment_ID);
// DO WHAT YOU NEED
}
add_action("add_attachment", \'cpt_from_attachment\');