How to restrict images in v3.5 Media Library modal to only those from a specific post id?

I am not sure is this what you are looking for. This code will “lock” uploads to show only “Uploaded to this post” in media panel

add_action( 'admin_footer-post-new.php', 'firmasite_mediapanel_lock_uploaded' );
add_action( 'admin_footer-post.php', 'firmasite_mediapanel_lock_uploaded' );
function firmasite_mediapanel_lock_uploaded() { ?>
  <script type="text/javascript">
    jQuery(document).on("DOMNodeInserted", function(){
        // Lock uploads to "Uploaded to this post"
        jQuery('select.attachment-filters [value="uploaded"]').attr( 'selected', true ).parent().trigger('change');
    });
  </script>
<?php }

Leave a Comment