5

单击“设置特色图像”按钮时,如何连接到现有的 wp.media 对象并获取附件 ID?

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

4

1 回答 1

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

});
于 2015-05-21T23:28:15.877 回答