Wordpress wp.media特色图片ID

HWD*_*HWD 6 javascript wordpress wp-editor

如何在单击"设置特色图像"按钮时挂钩到现有的wp.media对象并获​​取附件ID?

我一直在看的wp.media教程似乎都是从创建一个新的wp.media框架开始的,但我只是想监听来自现有的事件(由wp_editor()函数呈现),特别是"Set"特色图片"活动.

d79*_*d79 5

尝试使用该wp.media.featuredImage对象,更具体地说,它frame()get()方法:

// 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 );

});
Run Code Online (Sandbox Code Playgroud)