我想删除“alternate post" (Apróhirdetések menu)附件。当我点击”清空垃圾箱“时,我需要删除所有备用帖子和备用帖子附件删除。
我有两个半解决方案。
单击此按钮,然后运行脚本。
按钮代码:
<button data-toggle="tooltip" data-placement="top" title="<?php _e('Delete','theme-name');?>" onclick="javascript:cs_delete_directory_post('<?php echo esc_js(admin_url('admin-ajax.php'));?>','<?php echo esc_js($post->ID);?>')" type="button" class="tolbtn close close-<?php echo intval($post->ID); ?>" data-dismiss="alert"><em class="icon-trash-o"></em></button>
剧本:
function cs_delete_directory_post(admin_url, post_id){
if(confirm('Delete Post')){
"use strict";
var dataString = 'post_id=' + post_id+'&action=cs_delete_directory_post';
jQuery(".close-"+post_id).html('<i style="color:#fe9909;" class="icon-spinner8 icon-spin"></i>');
jQuery.ajax({
type:"POST",
url: admin_url,
data: dataString,
success:function(response){
jQuery(".attachment-thumbnail").remove();
jQuery(".post-"+post_id).remove();
}
});
}
return false;
}
插件:
function wpse_188427_delete_post_media( $post_id ) {
$attachments = get_posts(
array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_status' => 'any',
'post_parent' => $post_id,
)
);
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->ID );
}
}
add_action( 'delete_post', 'wpse_188427_delete_post_media' );
add_action( 'wp_trash_post', 'wpse_188427_delete_post_media' );
还需要更多信息吗?非常感谢。