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 have tried dbDelta and $wpdb->query, they does not work. Does anyone has any ideas?

share|improve this question
    
What is the error? You can dump it with the following call right after you executed the statement: $e = $wpdb->query($sql); die(var_dump($e)); –  Thomas Apr 26 '12 at 8:47
add comment

2 Answers

up vote 0 down vote accepted

According to this forum entry, truncate does not work. I would guess that since it's such a destructive query, that it's filtered by the class. There is also this Trac Post, which if I am reading it right, disallows DDL statements.

share|improve this answer
    
Well, maybe I use DELETE instead of truncate. –  goodseller Apr 26 '12 at 14:51
    
@goodseller Not sure what you're trying to do, so it might not be important to you--but note that DELETE does not reset any auto-incrementing columns. So even though your table will be empty, the next item ID will pick up where the last auto- incremented value left off. –  MathSmath Apr 26 '12 at 19:53
    
@MathSmath Yeah~ That's true, so true. However is there any way to do so? –  goodseller Apr 27 '12 at 4:02
    
I found it: $wpdb->query("ALTER TABLE tableName AUTO_INCREMENT=0") Thanks @MathSmath :) –  goodseller Apr 27 '12 at 5:37
add comment

As try today, truncate is WAY BETTER that DELETE, because DELETE broke the site, and trucate just empty the table, here is the working code :

global $wpdb;

$wpdb->query('TRUNCATE TABLE wp_posts');
share|improve this answer
add comment

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.