21

I would like to get last inserted id after $wpdb->insert().I got a solution with $wpdb->insert_id(); but unfortunately which retrieves the primary key plus an additional zero. ie, consider my primary key (or inserted id) is 2 $wpdb->insert_id(); retruns 20 .whats wrong with this method?anybody can please help me.

Aadi
  • 6,959
  • 28
  • 100
  • 145

1 Answers1

43

The insert_id is a property, not a method. Try it without the () at the end, see what you get.

jay.lee
  • 19,388
  • 8
  • 39
  • 38
  • its not the last ID ! please answer this question – zEn feeLo Mar 25 '19 at 02:09
  • From the comment for $insert_id in the code: `The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).`. This is the ID from an auto increment. If your inserting into a table without an auto increment you have to already know the ID unless your using UUID rather than INT. – Lightbulb1 Nov 04 '19 at 16:16