0

Trying to alter a database in Wordpress and adding new columns to it. Here is the code:

function new_columns_users(){

    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();
    $table_name = $wpdb->prefix . "users";

    $sql = "ALTER TABLE $table_name ADD (
        gender varchar(10),
        test varchar(10)
        ) $charset_collate;";

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );
}

This doesn't add the new columns in the database. I feel like I tried everything, what is wrong with this query?

6
  • do you execute the query somewhere in your code? Commented Jan 22, 2018 at 15:31
  • Possible duplicate of alter table add MULTIPLE columns AFTER column1 Commented Jan 22, 2018 at 15:32
  • yes this gets executed already checked with an error log Commented Jan 22, 2018 at 15:32
  • Your syntax is wrong. Commented Jan 22, 2018 at 15:32
  • checked out the other answer but still not sure how to place $charset_collate in the answer they gave. Commented Jan 22, 2018 at 15:39

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.