2

I'm trying to update a channel entry using the Channel API function save_entry.

ee()->load->library('api');
ee()->api->instantiate('channel_entries');

// Create input array
$data = array('field_id_'.$this->helper->get_field_id('booking_user') => $member_relationship);

// Update booking entry
$booking = ee()->api_channel_entries->save_entry($data, $this->channel, $booking_id);

This is my code and it's giving back this error

[29-May-2014 14:53:51 UTC] array(2) {
  ["title"]=>
  string(13) "missing_title"
  ["url_title"]=>
  string(26) "unable_to_create_url_title"
}

I don't want to update the title because it doesn't need to be changed.

My question is how can I update a channel entry without including a title?

2
  • 2
    OK, with a bit more digging I've found out that the save_entry function is actually terrible and will wipe out all data if you don't include it in the data array. Meaning I can't update one single field if I need to without including every other field in that entry. the save_entry() function is completely useless in my opinion for updating entries. May 29, 2014 at 15:29
  • You can answer your own question after 24 hours - can you come back and do that? May 29, 2014 at 22:42

1 Answer 1

3

As per your comments, you've already figured out the rather large annoyance of needing to pass all pre-existing fields with the save_entry function or else having them wiped out. I wanted to post an answer here though because there are a couple considerations I've come across when doing entry updates with my add-ons:

1) If you do not need the update to trigger the EE system from explicitly noticing it and then triggering other hooks or dependencies, you can just use the EE Database Class to do a simple database update query and update that particular field directly. This carries with it the added benefit that a session does not need to be initiated to make the update, so you can use this method for automated tasks or when the logged-in user does not have permissions.

2) If you DO need to update with save_entry in order to trigger the cascade of EE hooks and dependencies and are using a database 'select all' query to fill in your old values, then to keep the edit_date correct you need to unset the old edit_date and let EE fill this part in automatically. I've posted an answer with some code for doing this a few weeks back, which may be of some use: Using Channel API save_entry to update an entry

Your Answer

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

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