Hi @mountainthemes
There are tutorials showing how to create a new post however, it looks like your code above is for editing only.
Can you clarify exactly which button is causing the issue? Is it the one inside the popup? Or is it the actual gallery field button?