WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't seem to find a simple reliable way to do this - perhaps?:

// delete row ##
global $wpdb;
$delete = $wpdb->query( 
         "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

share|improve this question
Not sure but shouldn't you use $wpdb instead of $this? – GhostToast Dec 4 '13 at 18:07
The SQL looks right if you have a table named wp_table_name which I doubt. There is also truncate. I don't see how this is a WordPress question though. – s_ha_dum Dec 4 '13 at 18:11
@s_ha_dum - thanks, the table_name is whitelisted.. I think using $wpdb makes this a WP question.. this is a WP plugin using a table in the WP DB.. I've added an answer below - thanks again! – Q Studio Dec 4 '13 at 18:17
But it isn't a $wpdb error. It is a just a SQL error. – s_ha_dum Dec 4 '13 at 18:53
isn't it true that all WordPress errors are PHP errors, by the same logic ;) – Q Studio Dec 4 '13 at 21:29
up vote 1 down vote accepted

Thanks @s_ha_dum - Truncate does the job nicely:

// delete row ##
global $wpdb;
$delete = $wpdb->query("TRUNCATE TABLE `wp_table_name`");
share|improve this answer

2 years late, but maybe this will help someone in the future :)

The correct syntax for deleting rows from a MySQL table is:

DELETE FROM `wp_table_name`
WHERE 1 = 1;
share|improve this answer

I would just modify Q Studio example to: global $wpdb; $table = $wpdb->prefix . 'table_name'; $delete = $wpdb->query("TRUNCATE TABLE $table");

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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