Support » Fixing WordPress » Delete all posts in Uncategorized thru mysql WordPress 2.9

Viewing 3 replies - 1 through 3 (of 3 total)
  • So what’s the problem?

    I need a query that will delete all posts in the category Uncategorized…

    I don’t see a table in wp_posts that sets the category

    Doing this in the admin will take forever…

    BACKUP ANY DATA BEFOREHAND, and be prepared for a restore (just incase, i’m not making any guarantees).

    Here’s one suggested approach..

    Run something like this in phpmyadmin.. (select your WP database first, else the query will fail saying DB not selected, etc..)

    SELECT * FROM wp_posts p
    JOIN wp_term_relationships r ON p.ID = r.object_id
    JOIN wp_term_taxonomy tt ON r.term_taxonomy_id = tt.term_taxonomy_id
    JOIN wp_term_taxonomy t ON tt.term_id = t.term_id
    WHERE t.term_id = 2

    Where 2 would be the ID for said category (change as appropriate). The result should get you all the posts that match your given category, once you have those listed, firstly look at the results, to see if you can spot any incorrect results..

    If they’re ok , use Phpmyadmin to delete them in bulk from the result set (select all, “with selected” -> drop (ie.delete))… you can set phpmyadmin to show more results if you like (i think 300 is the default)..

    I’d say that’s just a safer approach, as i can’t vouch for how reliable any query i provide will be (i’ve no professional experience in MySQL – i learn by doing).

    I’d write you a query, but i’d have to create a mass amount of posts just to test the queries, and honestly i’ve not got the patience to be running delete simulations right now, no offense intended… ( i’ve just cleaned the DB out after the last round of delete query testing i helped with ).

    If you hold out, someone might offer a joined query for you, again though, be sure to backup your data, and be prepared to restore it just incase something does go wrong..

    NOTE: If you have a copy of this install in a test environment i’ll have a go writing one for you to test inside your test environment (cutting out my need to make lots of mock posts for testing the queries).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Delete all posts in Uncategorized thru mysql WordPress 2.9’ is closed to new replies.