1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can I delete old posts in WP?

Discussion in 'Blogging' started by bennyb, Jul 25, 2010.

  1. bennyb

    bennyb Regular Member

    Joined:
    Feb 8, 2009
    Messages:
    261
    Likes Received:
    72
    Location:
    Uranus
    Good day folks.

    I run three autoblogs and I am at the point where I have only 20% left available out of 40gb space. My databases are over 1 gig combined and each blog has 100.000+ posts. I want to purge some old posts but don't know any plugins or sql queries to do it. And I definately can't do it manually.

    Is there any plugins that would allow me to delete posts made before certain date?
     
  2. greenfish

    greenfish Newbie

    Joined:
    Aug 11, 2008
    Messages:
    4
    Likes Received:
    0
    There is a wordpress "bulk-delete" plugin.
    Also "bulk-move"
     
  3. trapmuzik

    trapmuzik Junior Member

    Joined:
    Mar 20, 2009
    Messages:
    192
    Likes Received:
    22
    you can try the following:

    Code:
    <?php
    include('wp-blog-header.php');
    
    global $wpdb;
    
    $posts = $wpdb->get_results("SELECT id from $wpdb->posts WHERE post_date < 'YYYY-MM-DD'");
    
    foreach ($posts as $post){
         wp_delete_post($post->id);
    }
    ?>
    
    
    you might also want to include a LIMIT in the query if you have more than a few thousand posts