Skip to content

Instantly share code, notes, and snippets.

@zmf
Created October 27, 2020 00:41
Show Gist options
  • Save zmf/077de84b1516996fd7b79e952ee21992 to your computer and use it in GitHub Desktop.
Save zmf/077de84b1516996fd7b79e952ee21992 to your computer and use it in GitHub Desktop.
WordPress: delete attachments without author
function delete_attachments_without_author()
{
foreach (get_posts(['post_type' => 'attachment', 'posts_per_page' => -1]) as $att) {
if (!$att->post_author) {
wp_delete_post($att->ID, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment