WordPress.org

Ready to get started?Download WordPress

Forums

Delete old posts programmatically (1 post)

  1. scrollpost
    Member
    Posted 2 years ago #

    I want to delete old posts programmatically.
    I found smatterings of code but usually more complicated than I require.

    I put this together to delete posts older than 120 days.

    Will it work?

    <?php
    require_once 'wp-load.php';

    global $wpdb;

    $expireds = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE DAY(TIMEDIFF(NOW(), post_date_gmt)) >=120");

    foreach ($expireds as $expired) {
    wp_delete_post($post->id, true);
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic