Created
June 5, 2015 19:30
-
-
Save filipslavik/6c5330f0083e89897cf3 to your computer and use it in GitHub Desktop.
delete un-attached images
This file contains hidden or 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
<?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