Wordpress wp.media Image ID

How can I connect to an existing wp.media object and capture the attachment ID when I click the Set Image button?

The wp.media tutorials, with which I seem to start with creating a new wp.media frame, but I just want to listen to events coming from an existing one (using the wp_editor () function), in particular the "Set Favorite Image" event.

+6
source share
1 answer

Try using the wp.media.featuredImage object, or rather its frame() and get() methods:

 // on featured image selection... wp.media.featuredImage.frame().on( 'select', function(){ // ...get the attachment ID var attachment_id = wp.media.featuredImage.get(); console.log( attachment_id ); }); 
+4
source

Source: https://habr.com/ru/post/986687/


All Articles