public static function delete_all_attachment( $post_ID, $force = false ) {

		if ( get_post_status( $post_ID ) === false ) {
			return false;
		}

		$counter = 0;

		$attachments = get_posts(
			[
				'post_type'      => 'attachment',
				'posts_per_page' => 100,
				'post_status'    => 'any',
				'post_mime_type' => 'image/jpeg, image/png, image/gif',
				'post_parent'    => $post_ID,
			]
		);

		foreach ( $attachments as $attachment ) {
			if ( wp_delete_attachment( $attachment->ID, $force ) !== false ) {
				$counter++;
			}
		}

		return $counter;
	}
public static function delete_all_attachment( $post_ID, $force = false ) {

		if ( get_post_status( $post_ID ) === false ) {
			return false;
		}

		$counter = 0;

		$attachments = get_posts(
			[
				'post_type'      => 'attachment',
				'posts_per_page' => 100,
				'post_status'    => 'any',
				'post_mime_type' => 'image/jpeg, image/png, image/gif',
				'post_parent'    => $post_ID,
			]
		);

		foreach ( $attachments as $attachment ) {
			if ( wp_delete_attachment( $attachment->ID, $force ) !== false ) {
				$counter++;
			}
		}

		return $counter;
	}
public static function delete_all_attachment ( $ post_ID , $ force = false ) { if ( get_post_status ( $ post_ID ) === false ) { return false ; } $ counter = 0 ; $ attachments = get_posts ( [ 'post_type' => 'attachment' , 'posts_per_page' => 100 , 'post_status' => 'any' , 'post_mime_type' => 'image/jpeg, image/png, image/gif' , 'post_parent' => $ post_ID , ] ) ; foreach ( $ attachments as $ attachment ) { if ( wp_delete_attachment ( $ attachment -> ID , $ force ) !== false ) { $ counter ++ ; } } return $ counter ; }
Deletes an attachment and all of its derivatives.

@since 1.0.3

@param int     $post_ID → post id.
@param boolean $force   → force deletion.

@return int|false → attachments deleted.
Deletes an attachment and all of its derivatives .