最终使用ajax。。。
html;
<a class="remImage" name="<?php echo $attachment->ID; ?>" href="#"><?php _e(\'delete\');?></a> <input type="hidden" id="att_remove" name="att_remove[]" value="<?php echo $attachment->ID; ?>" />
<input type="hidden" name="nonce" id="nonce" value="<?php echo wp_create_nonce( \'delete_attachment\' ); ?>" />
jquery
$(\'.remImage\').live(\'click\', function() {
var attID = jQuery(this).attr(\'name\');
jQuery.ajax({
type: \'post\',
url: \'/wp-admin/admin-ajax.php\',
data: {
action: \'delete_attachment\',
att_ID: jQuery(this).attr(\'name\'),
_ajax_nonce: jQuery(\'#nonce\').val(),
post_type: \'attachment\'
},
success: function() {
console.log(\'#file-\'+attID)
$(\'#file-\'+attID).fadeOut();
}
});
在函数中。php
add_action( \'wp_ajax_delete_attachment\', \'delete_attachment\' );
function delete_attachment( $post ) {
//echo $_POST[\'att_ID\'];
$msg = \'Attachment ID [\' . $_POST[\'att_ID\'] . \'] has been deleted!\';
if( wp_delete_attachment( $_POST[\'att_ID\'], true )) {
echo $msg;
}
die();
}