I am attempting to resolve a problem I continue to have with the media library.
Essentially, what I am looking to do is "automatically" assign media which is uploaded from a custom post type "edit post" page to a predefined category.
Based on other answers on this site I have found various people discussing solution (one of these links is below) which allow you to "manually" assign a category to media library elements. My aim however is to somehow define specific post types and the associating category which should be applied.
At the same time I would also like the ability to restricting a "specific post type" so when the media library lightbox is requested from the edit post page that the "media library" ONLY shows items within the categories I define.
I know this might sound a bit confusing so let me provide a quick example.
Let's say I have a custom post type called "employee news". Now let's say that someone proceeds to add/edit a post within this custom post type. Let's further assume that he now uses the editor to add content and now want to add one/more images. As expected he would select the "add media" button above the editor and either (a) upload a new image or (b) select an image from the media library. THESE are the two areas I am talking about.
What I need is the correct code to put into my functions.php file so that either one or both of the following can be set individually:
(a) Ability to specify a custom post type and define the hidden category name to be associated with any file uploaded to the media library.
(b) Ability to specify a custom post type and define the "restricted categories" to be used when presenting the files available for the user to select from.
How can this be achieved correct?
Related Question related to Category assignment of media elements: Can I add a Category Metabox to attachment?
Related Question related to conditional logic related to the media library: Conditional add_filter?