Created
October 27, 2020 00:41
-
-
Save zmf/077de84b1516996fd7b79e952ee21992 to your computer and use it in GitHub Desktop.
WordPress: delete attachments without author
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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