Please take a look at the following. This bit of code looks to schedule an event that deletes posts that contain a date in the form of post meta data on a daily basis.
The event get scheduled properly but the script is not deleting the posts as intended.
Here is the part that needs a more experienced eye. Most say it looks fine, but it is ot working.
NOTE: i have dates stored the yyyy-mm-dd format and posts certainly have the custom field attached.
function expired_post_delete() {
$todays_date = the_date('Y-m-d');
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'date',
'meta_query' => array(
array(
'key' => 'date',
'value' => $todays_date,
'type' => 'DATE',
'compare' => '<'
)
)
);
$posts = new WP_Query( $args );
// Cycle through each Post ID
foreach( $posts as $post) {
wp_delete_post($post_id);
}
}