$post_types, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_aitepc_expiry_date', // Ensure consistency with your meta key 'value' => $tomorrow, 'compare' => '<', 'type' => 'DATE' ) ) ); $expired_posts = new WP_Query($args); if ($expired_posts->have_posts()) { while ($expired_posts->have_posts()) { $expired_posts->the_post(); $post_id = get_the_ID(); $updated_post = array( 'ID' => $post_id, 'post_status' => 'draft' ); wp_update_post($updated_post); } wp_reset_postdata(); } } // Files include require_once plugin_dir_path(__FILE__) . 'functions.php'; require_once plugin_dir_path(__FILE__) . 'plugin-files/aitepc-settings.php'; require_once plugin_dir_path(__FILE__) . 'plugin-files/aitepc-expiry-metabox.php';