• Resolved diragusa

    (@diragusa)


    Im just wondering in detail how to implement this code:

    DELETE FROM wp_posts
    WHERE post_type = ‘post’
    AND DATEDIFF(NOW(), post_date) > 2

    Will this delete anything before two days ago? or will it delete just the day before and leave all the other posts before that.

    Say i have 5 posts dated monday. tuesday, wendsday, thursday, friday.
    but today is thursday, will the code above just delete wendsday and tuesday. but keep monday. or will it delete everything before thursday and keep friday as well.

    I also have multiple directories, will i have to add to the code.
    DELETE FROM wp_posts, wp_post_2, wp_posts_3 etc etc.

    Or will just wp_post find all the posts in all the directories of the multisite.

    Any insight would be great.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Please be sure to BACK UP your database before attempting any of these deletions!

    The first statement will delete all posts older than 2 days. To delete from separate tables you would need separate statements, one for each table.

    However, just deleting from wp_posts (and similar) tables, will probably leave lots of ‘orphan’ records in other tables.

    Posts normally have records attached through Custom Fields, Tags, and Categories. If you just delete the Posts, these other records will be left as orphans.

    I do not have a complete script for this, but maybe someone else can contribute one.

    Thread Starter diragusa

    (@diragusa)

    I got this to work. This will delete posts older than 6 months from the current time and date. Obviously you can change the interval to whatever you need.

    delete from wp_posts where post_date < DATE_SUB(NOW(), INTERVAL 6 MONTH)

    i saw this recently in the forums, could this work?

    That should delete from the wp_posts table but will leave ‘orphan’ records in other tables.

    Thread Starter diragusa

    (@diragusa)

    How is it implemented, in simple terms. Im not an expert. do i go into myphpadmin and add the script. or what exactly. is there a tutorial out there?

    hmmm when you speak of orhpans, i never found anything in the codex about it. im wondering how other people deal with delete posts prior to the present date.

    anyone?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Deleting Old Posts SQL Queries’ is closed to new replies.