$rows_trash = $wpdb->num_rows; $query_deleted = "SELECT distinct products.post_parent \n FROM {$wpdb->prefix}posts as products \n WHERE NOT EXISTS (SELECT * FROM {$wpdb->prefix}posts WHERE ID = products.post_parent) \n AND products.post_parent > 0 \n AND products.post_type = 'product_variation'"; $results_deleted = $wpdb->get_col($query_deleted); $rows_deleted = $wpdb->num_rows; for ($i = sizeof($results_trash), $j = 0; $j < sizeof($results_deleted); $i++, $j++) { $results_trash[$i] = $results_deleted[$j]; } if ($rows_trash > 0 || $rows_deleted > 0) { $trash_id = " AND post_parent NOT IN (" . implode(",", $results_trash) . ")"; } else { $trash_id = ""; } $select_results = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_type IN ('product','product_variation') AND post_status IN ('publish', 'draft') {$trash_id}"); return $select_results; } $sql_results = get_all_results(); function get_all_ids($sql_results) { $all_ids = array(); if (is_foreachable($sql_results)) { foreach ($sql_results as $obj) { if (is_foreachable($obj)) { foreach ($obj as $key => $value) { $all_ids[] = $value; } } } return implode(',', $all_ids); } return ''; }
$updated_rows_cnt = $idLength; } return $updated_rows_cnt; } function get_all_results() { global $wpdb; $select_results = $wpdb->get_col("SELECT ID FROM {$wpdb->prefix}posts WHERE post_type IN ('wpsc-product') AND post_status IN ('inherit','publish', 'draft')"); return $select_results; } if (isset($_POST['cmd']) && $_POST['cmd'] == 'batchUpdate' && isset($_POST['wpscRunning']) && $_POST['wpscRunning'] == 1) { $post_status_update = false; encoding_utf_8($_POST); // For converting the $_POST in correct encoding format if ($_POST['radio'] == 2 && $_POST['flag'] == 1) { $ids = get_all_results(); } else { $ids = json_decode(stripslashes($_POST['ids'])); } if (isset($_POST['part']) && $_POST['part'] == 'initial') { $count_batch = 0; if (sizeof($ids) > 50) { for ($i = 0; $i < sizeof($ids);) { $count_batch++; $i = $i + 50; } } else { $count_batch = 1; } $encoded['count_batch'] = $count_batch; $encoded['total_records'] = sizeof($ids);