Couldn’t come up with a good title for this.
I’ve got a build in WordPress where I have multiple image uploads using the built in WordPress media uploader. How it’s working is, after you upload and choose “insert”, jQuery is inserting the image path into a text field, which contains the ID. Once you save, the text field is saved in the options table.
Works perfectly if you only have 1 upload field. Once you add more uploads, every upload field gets saved with the same image path. Just need each upload button to only insert the value for it’s associated text field.
I’ve tried to use .each but couldn’t get it working correctly. Also tried using .attr(‘id’) to the value insert, but nothing doing there.
Here is my jQuery and the markup:
jQuery('.upload-button').click(function() {
formfield = jQuery('.upload').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('.upload').val(imgurl);
tb_remove();
};
<div class="upload_field"
<input type="text" name="upload_one" id="upload_one" class="upload" value="" />
<input type="button" class="upload-button" value="Upload Image" />
</div>
<div class="upload_field"
<input type="text" name="upload_two" id="upload_two" class="upload" value="" />
<input type="button" class="upload-button" value="Upload Image" />
</div>
<div class="upload_field"
<input type="text" name="upload_three" id="upload_three" class="upload" value="" />
<input type="button" class="upload-button" value="Upload Image" />
</div>
For further info, here is the uploader setup I’m using: http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/
Any help, as always, is greatly appreciated.
Just need to be able to specify the input field that the value is inserted into.