WordPress at a glance

wp_delete_auto_drafts() WP 1.0

Delete auto-drafts for new posts that are > 7 days old.

  • Global. wpdb. $wpdb WordPress database abstraction object.
Works based on: wp_delete_post()

No Hooks.


Nothing (null).



Code of wp delete auto drafts: wp-includes/post.php VER 5.1.1

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 );

Related Functions

From tag: cron (schedule)

More from category: Revisions

No comments
    Hello, !     Log In . Register