Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Not sure but shouldn't you use $wpdb instead of $this? –  GhostToast Dec 4 '13 at 18:07
1  
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

1 Answer 1

up vote 0 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

Your Answer

 
discard

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.