INVP::delete_attachments( int $post_id )
Action hook callback. Deletes all a vehicle’s attachments when the vehicle is deleted.
On This Page
Parameters Parameters
- $post_id
-
(int) (Required)
Return Return
(void)
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' => apply_filters( 'invp_query_limit', 1000, __METHOD__ ),
)
);
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->ID );
}
// Delete the transients that hold this vehicle's photos.
delete_transient( 'invp_get_the_photos_images_' . $post_id );
delete_transient( 'invp_get_the_photos_image_urls_' . $post_id );
}
Expand full source codeCollapse full source codeView on Github