wp_delete_auto_drafts

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

Description

wp_delete_auto_drafts(); 

Usage

  1. if ( !function_exists( 'wp_delete_auto_drafts' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_delete_auto_drafts(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function wp_delete_auto_drafts() { 
  2. global $wpdb; 
  3.  
  4. // Cleanup old auto-drafts more than 7 days old. 
  5. $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); 
  6. foreach ( (array) $old_posts as $delete ) { 
  7. // Force delete. 
  8. wp_delete_post( $delete, true );