Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom meta filed with upload file functionality but the problem is I can't get the fileurl button value when hit "insert into Post" below are my jQuery code

    window.send_to_editor = function(html) 

    {
        dlink = jQuery('button.urlfile',html).attr('title');
        jQuery('#download_link').val(dlink);
        tb_remove();
    }


    tb_show('', 'media-upload.php?post_id=1&type=image&TB_iframe=true');
    return false;
share|improve this question
    
If you are uploading a file and not an image, it might be good to change "&type=image" to "&type=file" as a starting place. –  Jake Aug 12 '12 at 19:55
    
See this question, hints and source examples to the media uploader in wp 3.5. –  bueltge Jan 20 '13 at 11:46

3 Answers 3

<div>
    <label style="float:left; margin: 5px 5px 0 0;">Image 4:</label>
    <input type="text" id="image_4" name="image_4" value="" style="width: 550px; float:left; margin:0 5px;"/>
    <input id="_btn" class="upload_image_button" type="button" value="Upload Image" />
    <input type="hidden" name="image4_id" id="image4_id" value="<?php echo $image_id4; ?>" />
</div>

<script>
jQuery(document).ready(function () {
    var formfield;
    var id;
    jQuery('.upload_image_button').click(function () {
        jQuery('html').addClass('Image');
        formfield = jQuery(this).prev().attr('name');
        id = jQuery(this).next().attr('name');

        tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
        return false;
    });
    window.original_send_to_editor = window.send_to_editor;
    window.send_to_editor = function (html) {
        if (formfield) {
            fileurl = jQuery('img', html).attr('src');
            jQuery('#' + formfield).val(fileurl);

            imgclass = jQuery('img', html).attr('class');
            imgid = parseInt(imgclass.replace(/\D/g, ''), 10);
            jQuery('#' + id).val(imgid);

            tb_remove();
            jQuery('html').removeClass('Image');
        } else {
            window.original_send_to_editor(html);
        }
    };
});
</script>
share|improve this answer

Again. If you are using file upload, it is different than image upload. To get a FILE url, use: $(html).attr('href');

File upload:

window.send_to_editor = function(html){
    var file_url = $(html).attr('href');

    // Do something with those variables

    tb_remove();
};

Image upload:

window.send_to_editor = function(html){
    var file_url = $('img', html).attr('src'),
        classes  = $('img', html).attr('class'),
        id       = classes.replace(/(.*?)wp-image-/, '');

    // Do something with those variables

    tb_remove();
};
share|improve this answer

try this:

window.send_to_editor = function(html){
    dlink = jQuery('img',html).attr('src');
    jQuery('#download_link').val(dlink);
    tb_remove();
}
share|improve this answer
    
thanks for your help but I tried it out before and doesnt work since I upload is file not image :( –  idontknowhow Mar 24 '12 at 3:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.