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'm sorting out a long-neglected wordpress.org blog. It has over 100,000 pieces of trackback spam. How can I remove them all?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

To make this more WP-ish:

function wpse_delete_trackbacks()
{
    global $wpdb;

    $wpdb->query( $wpdb->prepare(
        "
            DELETE FROM %s WHERE `comment_type` = 'trackback'
        ",
        "{$wpdb->prefix}comments"
    ) );
}
share|improve this answer
    
Your quotes around trackback need fixing, it's too minor an edit for me to perform! –  fredley Apr 26 '12 at 13:08
    
@fredley »it's too minor an edit for me to perform« = ?? –  kaiser Apr 26 '12 at 13:09
1  
I don't have edit privileges, so my edits need to be at least 6 chars :-) –  fredley Apr 26 '12 at 13:10
    
Ah, ok. You could simply add a comment // Make the query safer: Use prepare ;) Or you could add a check if there´re any trackbacks and in this case, abort and output a message. Anyway: fixed it. –  kaiser Apr 26 '12 at 13:11

I gave up on finding an elegant solution and just used a MySQL sledgehammer to banish the spam:

DELETE FROM `wp_comments` WHERE `comment_type`="trackback"
share|improve this answer

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.