Which Hook? Hide attachments from specific post types in media library

as the title implies – I would like to suppress attachments of a specific post type(s) from showing up in the “Media Library”

Not asking for a code example, but if someone can point me to the right hook it would be much appreciated. Thanks!

1 Answer
1

For the media library you can use the pre_get_posts hook targeting upload.php by means of $pagenow, a global variable, or even better, because globals are the devils child, by means of get_current_screen(). I’m assuming you want to target the media modal tab too – because targeting only one, but not the other, doesn’t make much sense after all -, you can do that via the ajax_query_attachments_args hook.

Leave a Comment