I can’t seem to find a simple reliable way to do this – perhaps?:

// delete row ##
global $wpdb;
$delete = $wpdb->query( 
    $wpdb->prepare( 
         "DELETE * FROM `wp_table_name`"
    )
);

// return ##
$return = __('Table Emptied.');
if ( $wpdb->last_error ) {
    $return = $wpdb->last_error;
}

But this gives me the classic:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘* FROM wp_table_name’ at line 1

4 s
4

I would just modify Q Studio example to:

global $wpdb;
$table  = $wpdb->prefix . 'table_name';
$delete = $wpdb->query("TRUNCATE TABLE $table");

Leave a Reply

Your email address will not be published. Required fields are marked *