title: Delete expired posts in wordpress by date meta data custom field
body: <p>---Resolved: Code Works as shown---</p>
  
  <p>I have this piece of code that I think should work, but alas...</p>
  
  <p>If anyone could take a peek and see if there something obvious.  I have reviewed a lot of resources on the wordpress codex, but have tried all I can think of.</p>
  
  <pre><code>// expired_post_delete hook fires when the Cron is executed
  
  add_action( 'expired_post_delete', 'delete_expired_posts' );
  
  // This function will run once the 'expired_post_delete' is called
  
  function delete_expired_posts() {
  
  $todays_date = current_time('mysql');
  
  $args = array(
      'post_type' =&gt; 'post',
      'posts_per_page' =&gt; -1,
      'meta_key' =&gt; 'date',
      'meta_query' =&gt; array(
          array(
              'key' =&gt; 'date',
              'value' =&gt; $todays_date,
              'type' =&gt; 'DATE',
              'compare' =&gt; '&lt;'
              )
      )
  );
   $posts = new WP_Query( $args );
  
  // The Loop
  if ( $posts-&gt;have_posts() ) {
  
      while ( $posts-&gt;have_posts() ) {
          $posts-&gt;the_post();
          wp_delete_post(get_the_ID());
      }
  
  } else {
  // no posts found
  }
  /* Restore original Post Data */
  wp_reset_postdata();
  }
  
  // Add function to register event to WordPress init
  add_action( 'init', 'register_daily_post_delete_event');
  
  // Function which will register the event
  function register_daily_post_delete_event() {
  // Make sure this event hasn't been scheduled
  if( !wp_next_scheduled( 'expired_post_delete' ) ) {
      // Schedule the event
      wp_schedule_event( time(), 'daily', 'expired_post_delete' );
      }
  }
  </code></pre>