2

I'm working on an extension that indexes the content of the entry when publish form is submitted, but I need to know if the entry is a new one or an updated one, and in both case, I need the entry_id (the new one juste created or the old one).

Do you know a way to do that? Should I use an other hook?

--Solution--

In fact, entry_submission_end come with 3 parameters: entry_id, meta and data. If the entry is a new one, entry_id contains the new entry_id but $data['entry_id'] is 0, so you can have a condition on that to check if you are editing or creating an entry.

1
  • I knew it had something to do with that $data array...thank you for figuring this out! Commented Oct 21, 2015 at 12:29

3 Answers 3

2

I usually check if entry_id = 0 (for new entry)

$this->EE->input->get_post('entry_id') == 0
2

You can compare $meta['edit_date'] with $meta['entry_date'].

You will need to bring both dates to same format of course, as entry_date contains current timestamp, while edit_date is formatted as '%Y%m%d%H%i%s'

1
  • Hi Yuri, thanks, I thought about this solution but the entry date could be modified so it's not very safe.
    – pvledoux
    Commented Oct 2, 2013 at 8:29
0

If anyone is looking for an answer here still then there is a simple test.

Along with the post data will be a value for entry_id, this is related to the originating entry id. So if this value is 0 then it is a new entry, if this value is > 0 then it is an update to an existing entry.

eg,

if ($_REQUEST['entry_id'] === 0) { // new post } else { // existing post }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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