Post edit – Media Library – Only get images from current post

This will lock uploads to “Uploaded to this post” and will not show “All media items” or other options in WordPress media panels.

Add this code to your function.php file

    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');
            jQuery('#media-attachment-filters').remove();
        });
      </script>
    <?php }