1

Issue: I need to use the update function as per exact same format as below, the issue is with the conditional statement for id i.e. [ WHERE (id = 1 OR id = 2) AND status = true]

$wpdb->update(
    $tbl_request_log,
    array(
        'status'    =>  false,
    ), 
    array(
        'id'        =>  array($req1_id, $req2_id),
        'status'    =>  true,
    )
);
2

This is not posible with $wpdb->update(). If you check the source code, you will see these lines (lines 2150 - 2161), there is no way getting an OR in there:

foreach ( $where as $field => $value ) {
    if ( is_null( $value['value'] ) ) {
        $conditions[] = "`$field` IS NULL";
        continue;
    }

    $conditions[] = "`$field` = " . $value['format'];
    $values[] = $value['value'];
}

$fields = implode( ', ', $fields );
$conditions = implode( ' AND ', $conditions );

However, you can write your own query using prepare()

$wpdb->query($wpdb->prepare(
    "UPDATE `$tbl_request_log` SET `status` = false WHERE (`id` = %d OR `id` = %d) AND `status` = true",
    $req1_id,
    $req2_id
));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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