<?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;

$sql = "SELECT `posts`.`ID`
FROM `w2p_posts` AS `posts`
LEFT JOIN `w2p_bp_meta_data` AS `meta` ON (`meta`.`postId` = `posts`.`ID`)
LEFT JOIN w2p_term_relationships
    ON (`posts`.ID = w2p_term_relationships.object_id)
WHERE `meta`.postId IS NULL
  AND (w2p_term_relationships.term_taxonomy_id IN (0))
  AND `posts`.`post_type` = 'lot'";

$limit = 100;
$i = 0;
$wpdb->query($sql);
$result = $wpdb->get_col();

foreach ($result as $item) {
    $res = wp_delete_post($item, true);
    var_dump($res);
}
