<?php

if (!empty($_SERVER['DOCUMENT_ROOT'])) {
    die("Access denied");
}

define('CRON_TASKS_BASE_PATH', __DIR__);
define('WP_USE_THEMES', false);
require(CRON_TASKS_BASE_PATH . '/../../../../wp-load.php');

use auctionforge\inc\ImageUploader;

if (!is_plugin_active(basename(dirname(__DIR__)) . '/' . basename(dirname(__DIR__)) . '.php')) {
    die("Plugin AuctionForge disabled");
}

global $wpdb;

$limit = 100;
$i = 0;
while ($lots = get_posts(
    array(
        'post_type' => 'lot',
        'numberposts' => $limit,
        'post_status' => array('draft', 'trash', 'publish'),
        'offset' => $limit * $i,
        'lang' => '',
        'meta_query' => array(
            array(
                'key' => 'lot_id',
                'compare' => 'EXISTS'
            )
        )
    )
)) {
    $ids = [];
    /** @var WP_Post $lot */
    foreach ($lots as $lot) {
        $ids[] = $lot->ID;
    }
    var_dump($ids);
    $sql = "DELETE FROM " . $wpdb->posts . " WHERE ID IN (" . implode(",", $ids) . ")";
    $wpdb->query($sql);
    $i++;
}
