如何使用wordpress中的媒体上传来上传video文件?

我有一个post类型,用于上传wordpress中的横幅。 使用名称,图像/video和url的自定义字段。 默认媒体上传工作正常上传图像/video,但我的问题是我无法获得自定义字段的video基本url。

这是我的代码,无法获取videourl。 它只给我video文件名。

window.send_to_editor = function(html) { var imgurlar = html.match(/]+src=\"([^\"]+)\"/); var imgurl = imgurlar[1]; //image if( imgurl.length ){ jQuery('#wsp_media').val(imgurl); jQuery('#preview-wsp-media').html(''); } //video else{ var fileurl = jQuery(html); //above "html" carries only video name if I click on "none" button in media library //check if fileurl is a video ?? var fName = jQuery(fileurl).attr('href'); ext = fName.split('.').pop().toLowerCase(); var validVideos = [validVideos)) . "'"?>]; if(jQuery.inArray(ext, validVideos) == -1){ alert('invalid video file selected'); }else{ jQuery('#wsp_media').val(fName); jQuery('#preview-wsp-media').html('<img src="https://stackoverflow.com/questions/8926142/how-to-upload-video-file-using-media-upload-in-wordpress//wp-includes/images/crystal/video.png" style="max-width:30px; max-height:50px"/>'); } } tb_remove(); } 

我自己找到了解决方案。

在“media_send_to_editor”中添加filter

 add_filter('media_send_to_editor', 'media_editor', 1, 3); 

在输出html中附加videourl

 function media_editor($html, $send_id, $attachment ){ //get the media's guid and append it to the html $post = get_post($send_id); $html .= ''.$post->guid.''; return $html; } 

获取这样的媒体url

 window.send_to_editor = function(html) { ....... ....... var pathArray = html.match(/(.*)<\/media>/); var mediaUrl = pathArray != null && typeof pathArray[1] != 'undefined' ? pathArray[1] : ''; jQuery('#wsp_media').val(mediaUrl); ....... ....... }