Forums

Fool rushes in... (3 posts)

  1. hooopla
    Member
    Posted 6 years ago #

    I'm using the recently-released 'Auto-Delete Posts' plugin. It does something incredibly useful for me, but appears to have a flaw. I've tried contacting the author but haven't been able to reach him, so I'm (foolishly?) attempting to fix this problem myself.

    This plugin searches for posts that are older than NOW minus an interval that we select using the Options interface. For instance, if we select an expiration date of 1 week, then any post older than NOW-1 week is deleted.

    $query = "SELECT ID FROM $wpdb->posts WHERE post_date < NOW() - INTERVAL " . $expiration . " DAY";

    $ids = $wpdb->get_results($query);
    foreach ($ids as $id) {
    if ('' == $id->ID) { continue; }
    wp_delete_post($id->ID);
    }
    }

    Here is the problem: this query retrieves the id's of WP static "pages" as well as individual posts. (The page data is still in the template file, of course, but you have to relink to it using Manage > Pages.)

    How can I modify this query so that it selects posts only — and does not select "pages"?

    Thanks for your help!

  2. Kafkaesqui
    Moderator
    Posted 6 years ago #

    $query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < NOW() - INTERVAL " . $expiration . " DAY";

    This selects only published posts.

  3. hooopla
    Member
    Posted 6 years ago #

    Thank you, thank you, thank you! :-)

Topic Closed

This topic has been closed to new replies.

About this Topic