INVP::delete_attachments( int $post_id )

Action hook callback. Deletes all a vehicle’s attachments when the vehicle is deleted.


Parameters Parameters

$post_id

(int) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-invp.php

	public static function delete_attachments( $post_id ) {
		// Is $post_id a vehicle?
		if ( self::POST_TYPE !== get_post_type( $post_id ) ) {
			// No, abort.
			return;
		}

		$attachments = get_posts(
			array(
				'post_parent'    => $post_id,
				'post_status'    => 'inherit',
				'post_type'      => 'attachment',
				'posts_per_page' => -1,
			)
		);

		foreach ( $attachments as $attachment ) {
			wp_delete_attachment( $attachment->ID );
		}
	}