Is there an equivalent to INSERT IGNORE in the wpdb class? As I'm fetching and inserting a twitter feed and the field in which I store the tweet ID is keyed UNIQUE, I am aware that duplicates are going to occur and do not need Wordpress informing me of them in my PHP error log. (Note, I would write the query I need and $wpdb->prepare it, but for whatever reason, that throws a bunch of other errors [that I'd be happy to share though don't consider them relevant to this question]).

  • 3
    You could try to update first and then insert if nothing was updated. Or if you want a single SQL command: INSERT ... ON DUPLICATE KEY UPDATE ... – birgire Apr 18 '13 at 14:43
  • Thanks for your input. Just out of curiosity, why was your comment upvoted? Is INSERT IGNORE not the done thing? – Evan Rose Apr 18 '13 at 17:51
  • "ignoring errors" should be avoided in general, better to take care of it if you can - is my advice ;-) – birgire Apr 18 '13 at 18:11

To answer the question directly, there is $wpdb->update but nothing that will strictly duplicate INSERT IGNORE that I know of. If $wpdb->update, does not work I am fairly sure that you will need to write your own query and use $wpdb->query and $wpdb->prepare.

  • Thank you for your answer. I am obviously trying to do things the Wordpress way, but as I said, I'd tried writing my own query and using query and prepare. THAT SAID, I did NOT do things the Wordpress way when I'd tried that previously in that I was preparing incorrectly! Writing my own query and correcty passing an array of my $vals quieted Wordpress down. Thanks again. – Evan Rose Apr 18 '13 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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