0

At this moment i am trying to modify this plugin that deletes table rows to delete ONLY rows that don't contain the word "Cekanje" in the column "Status", this is the code and the solution i am trying to build, if anyone can help me:

$tableId = (int)$_POST['table_id'];
$idKey = sanitize_text_field($_POST['id_key']);
$idVal = (int)$_POST['id_val'];

$wpdb->delete($mySqlTableName, array($idKey => $idVal));
$columnsMeta = WDTConfigController::loadColumnsFromDB($tableId, array($idColName));

if (count($columnsMeta) == 0) {
    $returnResult['error'] = __('Supplied id column not exist.', 'wpdatatables');
    echo json_encode($returnResult);
    exit();
} else {
    $columnMeta = $columnsMeta[0];

    if ($columnMeta->id_column) {
        $idColumnKey = sanitize_text_field($columnMeta->orig_header);

        $deleteRowIds = $rows[$idColumnKey];

        foreach ($deleteRowIds as $rowId) {
            $rowId = (int)$rowId;

            if (empty($rowId)) {
                continue;
            }

            do_action('wpdatatables_excel_before_delete_row', $rowId, $tableId);

            $res = $wpdb->delete($mySqlTableName, array($idColumnKey => $rowId));

And this is the solution I am trying to do to prevent the deletion of rows with "Status" = "Cekanje"

$dontdelete = $wpdb -> get_row($wpdb->prepare("SELECT id FROM SaveContactForm7_1 WHERE id != $idKey"));

if($dontdelete)
{
    exit();
}

1 Answer 1

0

Actually wpdb delete function works with an array of data, so i just put two variables in and solved it.

    $wpdb->delete($mySqlTableName, array($idKey => $idVal, Status => "Cekanje"));

And solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.