0

I want to delete a column from a table in WordPress. I tried many ways but either they don't work or they delete the whole row. But I just want to remove the status column. I have a lot of tables and I can't delete them manually. Is there a solution in WordPress?

I used the following code but it doesn't work and it doesn't remove the column

function remove_status_database()
{
    $table_name ="wp_order_status";
    $column_name = "status";
    $drop_ddl = true;
    maybe_drop_column($table_name , $column_name ,$drop_ddl );
}

Example of the image .

alex dev
  • 3
  • 4
  • 1
    `$drop_ddl` should be a SQL query to delete that column as per the [maybe_drop_column](https://developer.wordpress.org/reference/functions/maybe_drop_column/#parameters) documentation and you have just passed the `true` value as SQL that will do nothing. In simple words, that function just provides you better validation for the table and column name which you are gonna delete and then execute your DROP column query `$wpdb->query( $drop_ddl );` line. – Vijay Hardaha Dec 22 '22 at 03:25

2 Answers2

0

Have you tried to do it with https://de.wordpress.org/plugins/wp-optimize/ ?

you can simple select the specific table and remove it.

hth Stefano

sCp
  • 11
  • 4
0

I found the answer to my question. I can do a column with the following sql command.

$wpdb->query("ALTER TABLE wp_order_license DROP status" );
F. Müller
  • 3,969
  • 8
  • 38
  • 49
alex dev
  • 3
  • 4