Legacy Documentation
You are using the documentation for version 4.3.8. Go here for the latest version.
ExpressionEngine Channel Entries API¶
Calling the Class¶
- 
class Api_channel_entries¶
- The Channel Entries class is called with the - api->instantiate()function:- ee()->load->library('api'); ee()->legacy_api->instantiate('channel_entries'); - Note - The API uses a Singleton pattern and does not currently support nesting of calls. Thus instantiating a new call while in the middle of a request may have unanticipated results. 
Function Reference¶
Save Entry¶
- 
Api_channel_entries::save_entry($data[, $channel_id = NULL[, $entry_id = 0[, $autosave = FALSE]]])¶
- Saves a new or existing channel entry. The data array must contain a title and data for all required fields. If the entry date or edit date are not included in the data array, current time will be used instead.: - ee()->api_channel_entries->save_entry($data, $channel_id, $entry_id, $autosave); - Parameters: - $data (array) – Entry data to submit
- $channel_id (int) – The channel ID for the new entry
- $entry_id (int) – The entry ID to update
- $autosave (boolean) – Whether the entry is being autosaved or not
 - Returns: - Whether the new entry was successfully created or updated - Return type: - Boolean - Example Usage: - ee()->load->library('api'); ee()->legacy_api->instantiate('channel_entries'); ee()->legacy_api->instantiate('channel_fields'); $data = array( 'title' => 'Breaking News Story!', 'entry_date' => '1256953732', 'edit_date' => '1351653729', 'field_id_6' => 'Some data', 'field_ft_6' => 'none', 'field_id_19' => 'More data', 'field_ft_19' => 'xhtml' ); ee()->api_channel_fields->setup_entry_settings($channel_id, $data); $success = ee()->api_channel_entries->save_entry($data, $channel_id); if ( ! $success) { show_error(implode('<br />', $this->api_channel_entries->errors)); } - See also - Api_channel_fields::setup_entry_settingsin the Channel Fields API.- Note - As part of the data normalization, custom data with a value of NULL is transformed to an empty string before database insertion. - Note - Successful submission requires a valid session exist for a user with the necessary posting privileges. 
Submit New Entry¶
- 
Api_channel_entries::submit_new_entry($channel_id, $data[, $autosave = FALSE])¶
- Deprecated since version 2.6: Use - Api_channel_entries::save_entryinstead.- This function will create a new channel entry. The data array must contain a title and data for all required fields. If the entry date or edit date are not included in the data array, current time will be used instead. - ee()->api_channel_entries->submit_new_entry((int) $channel_id, (array) $data); - Parameters: - $channel_id (int) – The channel ID for the new entry
- $data (array) – Entry data to submit
- $autosave (boolean) – Whether the entry is being autosaved or not
 - Returns: - Whether the new entry was successfully created - Return type: - Boolean - Note - As part of the data normalization, custom data with a value of NULL is transformed to an empty string before database insertion. 
Update Entry¶
- 
Api_channel_entries::update_entry($entry_id, $data[, $autosave = FALSE])¶
- Deprecated since version 2.6: Use - Api_channel_entries::save_entryinstead.- This function will update a channel entry. The data array must contain a title and data for all required fields. If the entry date or edit date are not included in the data array, current time will be used instead. - ee()->api_channel_entries->update_entry((int) $entry_id, (array) $data); - Parameters: - $entry_id (int) – The entry ID to update
- $data (array) – Entry data to submit
- $autosave (boolean) – Whether the entry is being autosaved or not
 - Returns: - Whether an entry was successfully updated - Return type: - Boolean - Note - As part of the data normalization, custom data with a value of NULL is transformed to an empty string before database insertion. 
Delete Entry¶
- 
Api_channel_entries::delete_entry($entry_ids)¶
- This function will delete one or more entries as well as some of their related data. The data array must contain an entry id, or an array of entry ids. - ee()->api_channel_entries->delete_entry((mixed) $entry_ids); - Parameters: - $entry_ids (mixed) – Integer or array of integers containing
entry_idsto delete
 - Returns: - Whether an entry was successfully deleted - Return type: - Boolean 
- $entry_ids (mixed) – Integer or array of integers containing
Entry Exists¶
- 
Api_channel_entries::entry_exists($entry_id)¶
- This function checks if an entry with a given id exists. - ee()->api_channel_entries->entry_exists((int) $entry_id); - Parameters: - $entry_id (int) – Entry ID to be verified
 - Returns: - Whether an entry exists - Return type: - Boolean 
Send Pings¶
- 
Api_channel_entries::send_pings($ping_servers, $channel_id, $entry_id[, $send_now = TRUE])¶
- Deprecated since version 2.7. - This function sends pings to a list of ping servers. The - submit_new_entry()and- update_entry()functions will automatically send pings if given- ping_serversin their data array.- $ping_serversshould be a list of ping server ids from the- exp_ping_serversdatabase table:- ee()->api_channel_entries->send_pings((array) $ping_servers, (int) $channel_id, (int) $entry_id); - Parameters: - $ping_servers (array) – Array of IDs of ping servers in the database
- $channel_id (int) – ID of the channel that contains the
$entry_id
- $entry_id (int) – ID of the entry you want to send pings for
- $send_now (boolean) – Set to FALSEto prevent pings from being sent
 - Returns: - Whether pings were sent - Return type: - Boolean 
Update Relationship Cache¶
- This function updates the relationship cache table. You should only need to use this function if you are manually changing relationship data, - submit_new_entry()and- update_entry()will automatically recompile relationship data:- ee()->api_channel_entries->update_related_cache((int) $entry_id);