Try this on for size:
add_action('save_post', function($post_id, $post, $update){
if ( $post->post_type === 'newcomer' && $post->post_status === 'publish' ) {
$attachments = get_attached_media( 'image', $post->ID );
$featured_id = get_post_thumbnail_id();
//unset the featured image by ID if it exists
unset($attachments[$featured_id]);
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->ID, false );
}
}
}, 10, 3);
Note: You can forgoe wrapping the foreach
statement in a conditional checking the state of the $attachments
variable as get_attached_media()
casts its result to an array internally. Of course if you wish to be prudent in the event core internals change then just cast it yourself or add back your conditional check.
Useful reference: http://codex.wordpress.org/Function_Reference/get_attached_media