Too much recursion error when chosing image from image library for two different meta boxes in one post

I think you’re running into a problem people mentioned in the comments to that story. Someone else posted about it here:

http://www.theenglishguy.co.uk/2010/01/24/multiple-media-uploads-in-wordpress-functions-php/

Basically, the JavaScript from that site should be modified to be more like this:

jQuery(document).ready(function() {

  var formlabel = 0;
  var old_send_to_editor = window.send_to_editor;
  var old_tb_remove = window.tb_remove;

  jQuery('.upload_image_button').click(function(){
    formlabel = jQuery(this).parent();
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    return false;
  });

  window.tb_remove = function() {
    formlabel = 0;
    old_tb_remove();
  }

  window.send_to_editor = function(html) {
    if(formlabel){
      imgurl = jQuery('img',html).attr('src');
      formlabel.find('input[type="text"]').value(imgurl);
      tb_remove();
    } else {
      old_send_to_editor();
    }
  }
});

From there, all you need to do is make sure all the buttons have the class 'upload_image_button', and make sure the button is a sibling to its corresponding text box and there are no other upload forms in the same parent element.

Leave a Comment