We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Getting the latest insert_id after a Channel API submit_new_entry() call

Development and Programming

chichilatte's avatar
chichilatte
43 posts
15 years ago
chichilatte's avatar chichilatte

Just for anyone out there wondering how to get the entry_id of an entry you’ve just created using the Channel Entries submit_new_entry() call…

if ($this->EE->api_channel_entries->submit_new_entry($my_channel_id, $my_new_entry_object) === FALSE)
{
    echo "Couldn't create new entry.";
}
else
{
    $query = $this->EE->db->query('SELECT LAST_INSERT_ID()');
    $row = $query->row_array();
    $entry_id = $row['LAST_INSERT_ID()'];
    echo 'New entry_id = '.$entry_id;
}

(the docs say use something like $entry_id = $this->EE->db->insert_id() which only ever returns 0 in my experience)

[EE 2.1.0 build 20100810]

Moved to Development and Programming by Moderator

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
15 years ago
Sue Crocker's avatar Sue Crocker

Hi, chichilatte. This is more of a programming question, so moving the thread to the Development forum.

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

I think you might be able to get the entry id here, after you’ve inserted your entry:

$this->EE->api_channel_entries->entry_id;
       
chichilatte's avatar
chichilatte
43 posts
15 years ago
chichilatte's avatar chichilatte

No way, thanks Rob! I wonder how you found that out?

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

Let’s just say the channel entries api and I have an intimate relationship.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.