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 am loading upload-media.php file using thickbox on front end where user can upload images to the post.

Question: How to I trigger the upload-media.php so the link "set featured image" shows up on image manager, just like we see when we click on "set featured image" link on backend.

Featured image

Here is the code for the thickbox:

jQuery('.upload_media_button').live('click', function() {
            current_item = jQuery(this);
             container = "."+current_item.attr('rel');
             var request = url.media_upload+'?type=image&TB_iframe=true';
             //alert(request);
             tb_show('Image Manager', request);
             return false;
        });

        window.send_to_editor = function(html) {
             var img_tag = jQuery('img',html);
             //var attachment_id = jQuery('img',html).attr('class').replace(/[^0-9]/g, '');
             current_item.siblings(container).prepend(img_tag).css("height: auto");
             tb_remove();
        }

I know I can take the attachment ID and set the featured image after form submission but that's the Plan B ;)

share|improve this question
2  
We already got jQuery 1.7.x - so please use .on() instead of .live(). –  kaiser Mar 10 '12 at 18:50
    
@Kaiser: Oh, Sure! :) –  Sisir Mar 11 '12 at 7:30
add comment

1 Answer 1

up vote 1 down vote accepted

To get the "Use as featured Image" link you have to pass post_id to the media-upload.php file with the url so the request will be changed to:

var post_id = 234 // retrive the post id via php
var request = url.media_upload+'?post_id='+post_id+'type=image&TB_iframe=true';

Make sure you add the post_id very first of the url. It didn't worked for me when i added the post_id to the last of the url.

UPDATE: Some javascript handling will be needed for the ajax response. Still working on to figure out that part. I will update my answer if i can figure it out.

share|improve this answer
    
Did you ever figure out how to handle the ajax response? –  Elliott Mar 23 '12 at 14:47
add comment

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.