Skip to content

Instantly share code, notes, and snippets.

@filipslavik
Created June 5, 2015 19:30
Show Gist options
  • Save filipslavik/6c5330f0083e89897cf3 to your computer and use it in GitHub Desktop.
Save filipslavik/6c5330f0083e89897cf3 to your computer and use it in GitHub Desktop.
delete un-attached images
<?php
$args = array(
'author' => 3,
'post_status' => 'any',
'post_mime_type'=>'image',
'post_type' => 'attachment',
'nopaging' => true,
'post_parent' => 0,
'date_query' => array('before' => '-10 day'),
);
$query = new WP_Query ($args);
while ($query->have_posts ()) {
$query->the_post ();
$id = get_the_ID ();
$the_author = get_the_author();
$date = get_the_date();
$title = get_the_title();
$url = wp_get_attachment_url($id);
echo "$id - $date - $the_author - $title - $url\n";
wp_delete_post( $id, true);
}
wp_reset_postdata ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment