WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

share|improve this answer

Your Answer


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.