Home » Php » php – How to update table value in wordpress with update query?

php – How to update table value in wordpress with update query?

Posted by: admin February 25, 2020 Leave a comment

Questions:

Here is the code, I am updating col name custom_status of wp_users table for post data user email. Insert works fine, but the update query is not working.

Code Here:

if (isset($_POST["email_type"]) == 'News' ) {
    $wpdb->update('wp_users', array('custom_status' => 'News'), WHERE, array('user_email' => $_POST["user_email"] ));
}

Thanks for the suggestions.

How to&Answers:

You should add third argument which row you will update for example:

if (isset($_POST["email_type"]) == 'News' ) {
    $wpdb->update('wp_users', array('custom_status' => 'News'), array( 'ID' => 1 ));
}

Hope help you.