如何在现有的wp.media对象中挂钩并在“设置特色图片”时获取附件ID。单击按钮?
我一直在关注的wp.media教程似乎都是从创建一个新的wp.media框架开始的,但我只是想监听来自现有框架的事件(由wp_editor()函数呈现) ,特别是"设置特色图片"事件
答案 0 :(得分: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 );
});