How can I hook into an existing wp.media object and grab the attachment ID when the “Set Featured Image” button is clicked?
The wp.media tutorials I’ve been looking at all seem to start by creating a new wp.media frame, but I just want to listen for events coming from an existing one (rendered by wp_editor() function), particularly the “Set Featured Image” event.
Try using the
wp.media.featuredImage
object, and more specifically itsframe()
andget()
methods: