Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I wrote a function, which should rename my attachments, based on the post title. Unfortunately this function created over 10.000 empty instances in my media-library, before I was able to stop it. The instances are all attached to a single post, which I could delete if it's necessary.

I'm really sorry to bother you with the ask for help, but I'm a bit scared to screw things up again.

share|improve this question
    
How exactly do these empty instances look like? –  toscho Mar 21 '13 at 0:26
    
hard to describe, cause they are invisible, like ghosts. I made a screenshot –  schwarzgrau Mar 21 '13 at 0:42
add comment

1 Answer

up vote 0 down vote accepted

Since I didn't expected an answer to this question I tried it with wp_delete_attachment();. I wrote this function on a random page of my site (since the site isn't live yet) and executed it from there.

$attac_kill_ids = range(1235, 22686); //fill an array with the post_ids from the empty instances                    
foreach( $attac_kill_ids as $kill_id ){
    $kill_post = get_post( $kill_id );
    if( $kill_post ) {
        wp_delete_attachment( $kill_id, true );
        echo '<br />killed #' . $kill_id;
    }
    else continue;
}

'delete' would be more precise, but 'kill' sounds more dangerous and keeps me concentrated thereby.

Then I used this line in phpMyAdmin to set the ID-counter back to 810

ALTER TABLE wp_posts AUTO_INCREMENT=810
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.