I have a custom post type with a metabox text input area that I want to have a shortcode inserted into from a thickbox when a link is clicked on from the modal window. Using the code below right now it just closes the modal window when the insert button is clicked. Please tell me where I am going wrong.
I have the thick box opening fine.
The page that is rendered has the link as this:
echo '<td><a href="#" style="display:block" class="button insertdownload" id="download-'.$d->id.'">Insert</a></td>';
I have the jQuery call as:
jQuery('.insertdownload').click(function(){
var did = jQuery(this).attr('id');
did=did.replace('download-', '');
if (jQuery('#format').val()>0) {
jQuery('#my_new_field').val('[download id="' + did + '" format="' +
jQuery('#format').val() + '"]');
} else {
jQuery('#my_new_field').val('[download id="' + did + '"]');
}
window.parent.tb_remove();
});
I also have my metabox text field as:
<input type="text" size="25" name="myplugin_new_field" id="my_new_field">
This was the original code but I didn't want it to go to the editor window, I want it to go to my input field.
jQuery('.insertdownload').click(function(){
var win = window.dialogArguments || opener || parent || top;
var did = jQuery(this).attr('id');
did=did.replace('download-', '');
if (jQuery('#format').val()>0) win.send_to_editor('[download id="' + did + '" format="' + jQuery('#format').val() + '"]');
else win.send_to_editor('[download id="' + did + '"]');
});