Uses
Uses | Description |
---|---|
wp-includes/post.php: wp_delete_post() | Trash or delete a post or page. |
wp-includes/wp-db.php: wpdb::get_col() | Retrieves one column from the database. |
Delete auto-drafts for new posts that are > 7 days old.
File: wp-includes/post.php
function wp_delete_auto_drafts() { global $wpdb; // Cleanup old auto-drafts more than 7 days old. $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); foreach ( (array) $old_posts as $delete ) { // Force delete. wp_delete_post( $delete, true ); } }
Version | Description |
---|---|
3.4.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_delete_auto_drafts