bp_media_delete_orphaned_attachments()
Delete orphaned attachments uploaded
Description
Source
File: bp-media/bp-media-functions.php
function bp_media_delete_orphaned_attachments() {
$orphaned_attachment_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'fields' => 'ids',
'posts_per_page' => - 1,
'meta_query' => array(
array(
'key' => 'bp_media_saved',
'value' => '0',
'compare' => '=',
),
),
);
$orphaned_attachment_query = new WP_Query( $orphaned_attachment_args );
if ( $orphaned_attachment_query->post_count > 0 ) {
foreach( $orphaned_attachment_query->posts as $a_id ) {
wp_delete_post( $a_id, true );
}
}
}
Changelog
| Version | Description |
|---|---|
| BuddyBoss 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.