如果有人与这样的问题发生冲突,我会这样解决:
$attachments = get_posts( array(
\'post_type\' => \'attachment\',
\'posts_per_page\' => -1,
\'post_status\' => \'any\',
\'post_parent\' => $post_id
) );
$thumbId = get_post_thumbnail_id($post_id);
foreach ( $attachments as $attachment ) {
if($thumbId != $attachment->ID) wp_delete_attachment( $attachment->ID, true );
}